Echoing an image

Thread Solved

Join Date: May 2008
Posts: 16
Reputation: Bulldawg is an unknown quantity at this point 
Solved Threads: 0
Bulldawg Bulldawg is offline Offline
Newbie Poster

Echoing an image

 
0
  #1
May 28th, 2008
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 = '<img src="pics/rankings/jfo.gif">';
$var2 = '<img src="pics/rankings/fo.gif">';
$var3 = '<img src="pics/rankings/sfo.gif">';
$var4 = '<img src="pics/rankings/c.gif">';
$var5 = '<img src="pics/rankings/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";
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echoing an image

 
0
  #2
May 28th, 2008
first what is block? variable? you can try removing the quotes too since it is numeric
maybe something like this:
  1. if($block>99.9){
  2. echo $var1;
  3. }elseif($block>199.9){
  4. echo $var2;
  5. }
  6. //and so on
Last edited by ProfessorPC; May 28th, 2008 at 7:47 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 16
Reputation: Bulldawg is an unknown quantity at this point 
Solved Threads: 0
Bulldawg Bulldawg is offline Offline
Newbie Poster

Re: Echoing an image

 
0
  #3
May 28th, 2008
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 "<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/jfo.gif">';
$var2 = '<img src="pics/rankings/fo.gif">';
$var3 = '<img src="pics/rankings/sfo.gif">';
$var4 = '<img src="pics/rankings/c.gif">';
$var5 = '<img src="pics/rankings/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 "</td><td align=center>";
echo $row['arr_airport'];
echo "</td><td align=center>";
echo $row['date'];
echo "</td></tr>";
}
echo "</table>";
?>
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echoing an image

 
0
  #4
May 28th, 2008
ok so block is a field from the db. you need to have that included in your if statement.
  1. if($row['block']>99.9){
  2. echo $var1;
  3. }elseif($row['block']>399.9){
  4. echo $var2;
  5. }
if im understanding correctly this should work
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 16
Reputation: Bulldawg is an unknown quantity at this point 
Solved Threads: 0
Bulldawg Bulldawg is offline Offline
Newbie Poster

Re: Echoing an image

 
0
  #5
May 28th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echoing an image

 
0
  #6
May 28th, 2008
sure you can add it.
  1. }elseif($row['block']>99.9 && $row['flights']>319){
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 16
Reputation: Bulldawg is an unknown quantity at this point 
Solved Threads: 0
Bulldawg Bulldawg is offline Offline
Newbie Poster

Re: Echoing an image

 
0
  #7
May 28th, 2008
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!!!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echoing an image

 
0
  #8
May 28th, 2008
get somebody outside of the project helps alot. your welcome
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 16
Reputation: Bulldawg is an unknown quantity at this point 
Solved Threads: 0
Bulldawg Bulldawg is offline Offline
Newbie Poster

Re: Echoing an image

 
0
  #9
May 29th, 2008
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 "<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>";
echo $row['arr_airport'];
echo "</td><td align=center>";
echo $row['date'];
echo "</td></tr>";

}

echo "</table>";
?>

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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Echoing an image

 
0
  #10
May 29th, 2008
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.
Last edited by ProfessorPC; May 29th, 2008 at 12:51 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC