943,950 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1972
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
May 28th, 2008
0

Echoing an image

Expand Post »
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";
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bulldawg is offline Offline
16 posts
since May 2008
May 28th, 2008
0

Re: Echoing an image

first what is block? variable? you can try removing the quotes too since it is numeric
maybe something like this:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
May 28th, 2008
0

Re: Echoing an image

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>";
?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bulldawg is offline Offline
16 posts
since May 2008
May 28th, 2008
0

Re: Echoing an image

ok so block is a field from the db. you need to have that included in your if statement.
php Syntax (Toggle Plain Text)
  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
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
May 28th, 2008
0

Re: Echoing an image

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bulldawg is offline Offline
16 posts
since May 2008
May 28th, 2008
0

Re: Echoing an image

sure you can add it.
php Syntax (Toggle Plain Text)
  1. }elseif($row['block']>99.9 && $row['flights']>319){
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
May 28th, 2008
0

Re: Echoing an image

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!!!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bulldawg is offline Offline
16 posts
since May 2008
May 28th, 2008
0

Re: Echoing an image

get somebody outside of the project helps alot. your welcome
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007
May 29th, 2008
0

Re: Echoing an image

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bulldawg is offline Offline
16 posts
since May 2008
May 29th, 2008
0

Re: Echoing an image

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.
Reputation Points: 31
Solved Threads: 29
Posting Whiz in Training
ProfessorPC is offline Offline
270 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: DOMDocumet loadHTMLfile()
Next Thread in PHP Forum Timeline: Dynamically resize iframe containing php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC