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";
}

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

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>";
?>

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

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.

sure you can add it.

}elseif($row['block']>99.9 && $row['flights']>319){

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!!!!!

get somebody outside of the project helps alot. your welcome

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. :(

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.

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?

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

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?

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.

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>";
?>

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?!

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

$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";

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

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 "<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;
echo "</td><td align=left>";
echo $row;
echo "</td><td align=center>";
echo $row;
echo "</td><td align=center>";
echo $row;
echo "</td><td align=center>";
echo sprintf( "%4.1f", $row );
echo "</td><td align=center>";
echo sprintf( "%4.1f", $row );
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>1299.9 && $row>519){
echo $var4;
}elseif($row>799.9 && $row>319){
echo $var3;
}elseif($row>399.9 && $row>159){
echo $var2;
}elseif($row>99.9 && $row>39){
echo $var1;
}elseif($row>0){
echo $var5;
}
echo $row;
echo "</td><td align=center>";
$arrival = mysql_query("Select arr_airport from pireps where pilotid2 = ".$row." order by date_of_flight DESC LIMIT 0,1") or die(mysql_error());
while($arrive = mysql_fetch_array($arrival)){
echo $arrive;
}
echo "</td><td align=center>";
echo $row;
echo "</td></tr>";
}
echo "</table>";
?>

Do you want me to post the link to where the table result is?

I get everything good, except I don't know how to get that last entry from the arr_airport part of the table to display in the 'Currently In ' row.

ok i thought the pilotid was an int. so change the second query to:

$arrival = mysql_query("Select arr_airport from flight2 where pilotid2 = '".$row['pilotid1']."' order by date_of_flight DESC LIMIT 0,1") or die(mysql_error());

need the single quotes around '".$row['pilotid1']."'

Awesome......I think that does it!!!!! ( I replaced flight2 with pireps though) ;)
That basically does everything I want now. Like I said, I find my head spinning sometimes trying to understand all the code. I appreciate you giving your time to help!!

not a problem. must have forgot to take that out of my testing one i had setup. glad everything is working for you now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.