954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Echoing an image

Can someone help me with this one. I want to show the different images according to the criteria. It only returns the first image 'echo $var1' as it is. I guess I am trying to figure out how to do: greater than one number AND less than another number to show the appropriate image listed in my $var1,2,3,4,5. Thanks for any help anyone can give me.

$var1 = 'jfo.gif'; $var2 = 'fo.gif'; $var3 = 'sfo.gif'; $var4 = 'c.gif'; $var5 = 'sc.gif';

if(block > ("0")){
echo $var1;
} elseif(block > ("99.9")){
echo $var2;
} elseif(block > ("399.9")){
echo $var3;
} elseif(block > ("799.9")){
echo $var4;
} elseif(block > ("1299.9")){
echo $var5;
}else {
echo "work in progress";
}

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

first what is block? variable? you can try removing the quotes too since it is numeric
maybe something like this:

if($block>99.9){
echo $var1;
}elseif($block>199.9){
echo $var2;
}
//and so on
ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

Sorry, here is what I have so far, to help elaborate :) Of course, I am fairly new to this stuff. So, here is where I am.....I want the $var1,2,3,4,5 results to show up in the "echo $row['rank'];" section. Thanks again.


$query = "SELECT firstname, lastname, pilotid1, pilotid2, COUNT(flight_time) AS flights, SUM(block_time) AS block, SUM(flight_time) AS ftime, MAX(date_of_flight) AS date FROM members, pireps WHERE members.pilotid1 = pireps.pilotid2 GROUP BY pilotid1 ORDER BY flights DESC, block DESC, ftime DESC, date DESC";

$result = mysql_query($query) or die(mysql_error());

echo "";
echo "First Last Pilot ID Flights Block Time Flight Time Rank Currently In Last Flight";

while($row = mysql_fetch_array( $result )) {

echo "";
echo $row['firstname'];
echo "";
echo $row['lastname'];
echo "";
echo $row['pilotid1'];
echo "";
echo $row['flights'];
echo "";
echo sprintf( "%4.1f", $row['block'] );
echo "";
echo sprintf( "%4.1f", $row['ftime'] );
echo "";

$var1 = 'jfo.gif'; $var2 = 'fo.gif'; $var3 = 'sfo.gif'; $var4 = 'c.gif'; $var5 = 'sc.gif';

if(block > ("0")){
echo $var1;
} elseif(block > ("99.9")){
echo $var2;
} elseif(block > ("399.9")){
echo $var3;
} elseif(block > ("799.9")){
echo $var4;
} elseif(block > ("1299.9")){
echo $var5;
}else {
echo "in progress";
}

echo $row['rank'];
echo "";
echo $row['arr_airport'];
echo "";
echo $row['date'];
echo "";
}
echo "";
?>

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

ok so block is a field from the db. you need to have that included in your if statement.

if($row['block']>99.9){
echo $var1;
}elseif($row['block']>399.9){
echo $var2;
}

if im understanding correctly this should work

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

if($row['block']>1299.9){
echo $var4;
}elseif($row['block']>799.9){
echo $var3;
}elseif($row['block']>399.9){
echo $var2;
}elseif($row['block']>99.9){
echo $var1;
}elseif($row['block']>0){
echo $var5;
}

Ok, perfect, thanks. Now the above code works great. I want to add another variable in the elseif statement referencing another table in the database. Can I do that somehow in the same line? ie. }elseif($row['block']>99.9['flights']>319){ Now, that did not work for me, but can this be done something like that? Thanks.

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

sure you can add it.

}elseif($row['block']>99.9 && $row['flights']>319){
ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

Ok got it!!!!! I can't thank you enough ProfessorPC. I have struggled with that one for awhile now. Sometimes reading too much can just confuse a person more :) Thanks again!!!!!

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

get somebody outside of the project helps alot. your welcome

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

One last thing.....The code I have is:

$query = "SELECT firstname, lastname, pilotid1, pilotid2, COUNT(flight_time) AS flights, SUM(block_time) AS block, SUM(flight_time) AS ftime, arr_airport, MAX(date_of_flight) AS date FROM members, pireps WHERE members.pilotid1 = pireps.pilotid2 GROUP BY pilotid1 ORDER BY flights DESC, block DESC, ftime DESC, arr_airport, date DESC";

$result = mysql_query($query) or die(mysql_error());

echo "";
echo "First Last Pilot ID Flights Block Time Flight Time Rank Currently In Last Flight";

while($row = mysql_fetch_array( $result )) { echo ""; echo $row['firstname']; echo ""; echo $row['lastname']; echo ""; echo $row['pilotid1']; echo ""; echo $row['flights']; echo ""; echo sprintf( "%4.1f", $row['block'] ); echo ""; echo sprintf( "%4.1f", $row['ftime'] ); echo ""; $var1 = 'fo.gif'; $var2 = 'sfo.gif'; $var3 = 'c.gif'; $var4 = 'sc.gif'; $var5 = 'jfo.gif';

if($row['block']>1299.9 && $row['flights']>519){
echo $var4;
}elseif($row['block']>799.9 && $row['flights']>319){
echo $var3;
}elseif($row['block']>399.9 && $row['flights']>159){
echo $var2;
}elseif($row['block']>99.9 && $row['flights']>39){
echo $var1;
}elseif($row['block']>0){
echo $var5;
}

echo $row['rank'];
echo "";
echo $row['arr_airport'];
echo "";
echo $row['date'];
echo "";

}

echo "";
?>

How on earth can I get the last entry for 'arr_airport'? I have tried several things, but I can not get it to organize that column for output into the table by it's last entry. So DESC or ASC don't work, it just does it alphabetically. But I need the last item entered only for that field. I can't figure it out, even though it should be simple. :(

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

hm... you already have it grouped by then orderby other fields. this field is associated to one of the other fields previously order by correct? guess i am a little confused by the structure.
maybe if you could give me an idea of the data table setup it might help.

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 
hm... you already have it grouped by then orderby other fields. this field is associated to one of the other fields previously order by correct? guess i am a little confused by the structure. maybe if you could give me an idea of the data table setup it might help.

My inexperience is probably what gets confusing. :) As for the table structure, there are two tables in the database.
The members table has an ID(INT,AUTO_INCREMENT),pilotid1, firstname, lastname, password, email(all VARCHAR's)
The pireps table has an ID(INT,AUTO_INCREMENT),pilotid2,password, date_of_flight(DATE), flight_number, aircraft, block_time, flight_time, dep_airport, dep_time, arr_airport, arr_time(all VARCHAR's)

Is this what you meant?

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

would it be possible to get a couple examples so i can insert into my mock db and test?
ok i got the data in. give me a few minutes to use this query

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

ok your grouping this by pilotid. this is taking the info from the tables and displaying the information in one row per pilotid. and you want this to display with more then one row per pilotid?

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 
ok your grouping this by pilotid. this is taking the info from the tables and displaying the information in one row per pilotid. and you want this to display with more then one row per pilotid?

No, I just want one result per pilotid, but the last entry for arr_airport will indicate where the person last flew to. The way it is now, it shows a destination from arr_airport, just not the last one submitted into the database, which is what I want. Hope this all makes sense.

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

give this a try. i added another query to pull the arr_airport by date below. its pretty straight forward.

$query = "SELECT firstname, lastname, pilotid1, pilotid2, COUNT(flight_time) AS flights, SUM(block_time) AS block, SUM(flight_time) AS ftime, MAX(date_of_flight) AS date FROM members, pireps WHERE members.pilotid1 = pireps.pilotid2 GROUP BY pilotid1 ORDER BY flights DESC, block DESC, ftime DESC, date DESC";

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>First</th> <th>Last</th> <th>Pilot ID</th> <th>Flights</th> <th>Block Time</th> <th>Flight Time</th> <th>Rank</th> <th>Currently In</th> <th>Last Flight</th></tr>";

while($row = mysql_fetch_array( $result )) {

echo "<tr><td align=left>";
echo $row['firstname'];
echo "</td><td align=left>";
echo $row['lastname'];
echo "</td><td align=center>";
echo $row['pilotid1'];
echo "</td><td align=center>";
echo $row['flights'];
echo "</td><td align=center>";
echo sprintf( "%4.1f", $row['block'] );
echo "</td><td align=center>";
echo sprintf( "%4.1f", $row['ftime'] );
echo "</td><td align=center>";

$var1 = '<img src="pics/rankings/fo.gif">';
$var2 = '<img src="pics/rankings/sfo.gif">';
$var3 = '<img src="pics/rankings/c.gif">';
$var4 = '<img src="pics/rankings/sc.gif">';
$var5 = '<img src="pics/rankings/jfo.gif">';

if($row['block']>1299.9 && $row['flights']>519){
echo $var4;
}elseif($row['block']>799.9 && $row['flights']>319){
echo $var3;
}elseif($row['block']>399.9 && $row['flights']>159){
echo $var2;
}elseif($row['block']>99.9 && $row['flights']>39){
echo $var1;
}elseif($row['block']>0){
echo $var5;
}

echo $row['rank'];
echo "</td><td align=center>";
$arrival = mysql_query("Select arr_airport from pireps where pilotid2 = ".$row['pilotid1']." order by date_of_flight DESC LIMIT 0,1") or die(mysql_error());
while($arrive = mysql_fetch_array($arrival)){

echo $arrive['arr_airport'];

}
echo "</td><td align=center>";
echo $row['date'];
echo "</td></tr>";

}

echo "</table>";
?>
ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

That gave me only one result due to an error in the arr_airport part. It returned this result n the table for arr_airport:
Unknown column 'CPC912' in 'where clause'
So, it seems it didn't like something when grabbing the pilot id?!

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

can you post what you have for line 44? (the query)

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

$query = "SELECT firstname, lastname, pilotid1, pilotid2, COUNT(flight_time) AS flights, SUM(block_time) AS block, SUM(flight_time) AS ftime, MAX(date_of_flight) AS date FROM members, pireps WHERE members.pilotid1 = pireps.pilotid2 GROUP BY pilotid1 ORDER BY flights DESC, block DESC, ftime DESC, date DESC";

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

The CPC912 is an aircraft type correct?
sorry its the other query i was needing. the second query and while loop.

ProfessorPC
Posting Whiz in Training
270 posts since Dec 2007
Reputation Points: 31
Solved Threads: 29
 

Here is the whole thing, with the suggested changes you had above.....

$query = "SELECT firstname, lastname, pilotid1, pilotid2, COUNT(flight_time) AS flights, SUM(block_time) AS block, SUM(flight_time) AS ftime, MAX(date_of_flight) AS date FROM members, pireps WHERE members.pilotid1 = pireps.pilotid2 GROUP BY pilotid1 ORDER BY flights DESC, block DESC, ftime DESC, date DESC";

$result = mysql_query($query) or die(mysql_error()); echo ""; echo "First Last Pilot ID Flights Block Time Flight Time Rank Currently In Last Flight"; while($row = mysql_fetch_array( $result )) { echo ""; echo $row['firstname']; echo ""; echo $row['lastname']; echo ""; echo $row['pilotid1']; echo ""; echo $row['flights']; echo ""; echo sprintf( "%4.1f", $row['block'] ); echo ""; echo sprintf( "%4.1f", $row['ftime'] ); echo ""; $var1 = 'fo.gif'; $var2 = 'sfo.gif'; $var3 = 'c.gif'; $var4 = 'sc.gif'; $var5 = 'jfo.gif'; if($row['block']>1299.9 && $row['flights']>519){ echo $var4; }elseif($row['block']>799.9 && $row['flights']>319){ echo $var3; }elseif($row['block']>399.9 && $row['flights']>159){ echo $var2; }elseif($row['block']>99.9 && $row['flights']>39){ echo $var1; }elseif($row['block']>0){ echo $var5; } echo $row['rank']; echo ""; $arrival = mysql_query("Select arr_airport from pireps where pilotid2 = ".$row['pilotid1']." order by date_of_flight DESC LIMIT 0,1") or die(mysql_error()); while($arrive = mysql_fetch_array($arrival)){ echo $arrive['arr_airport']; } echo ""; echo $row['date']; echo ""; } echo ""; ?>

Bulldawg
Newbie Poster
16 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You