Jump to content

[SOLVED] Another display problem... for Barand again...


hellouthere

Recommended Posts

I am trying to take the most recent flightid for each callsign in the database... this is the query i have, adapted from the las one Barand gave me...

 

		$lstsql = "SELECT p.realname, h.IDPIREP, h.CreatedON
	FROM pilots AS p LEFT JOIN pirep AS h ON p.ID = h.IDPilot
	WHERE pos!=''
	GROUP BY p.realname
	ORDER BY p.ID";

 

this is after i print the table header...

 

for ($i=0; $i<$number; $i++) {

   list($lstname, $lstid, $lstdate) = mysql_fetch_row($lstres);

 

i ave a pirep table with IDPIREP, IDPilot and CreatedON fields... these are the only relevant ones...

 

also a pilots table with ID (=IDPilot in pirep table)

 

the query above returns the oldest result...

 

Thanks in advance...

Link to comment
Share on other sites

You could, but mysql_result is the slowest way to access a result set, mysql_fetch_row() is the fastest.

 

<?php

$lstsql = "SELECT p.ID, p.realname, MAX(h.IDPirep) as latest
            FROM pilot p INNER JOIN pirep h ON p.ID = h.IDPilot
            GROUP BY p.ID";
$lstres = mysql_query($lstsql) or die (mysql_error().'<p>$lstsql</p>');

while (list($id, $pilot, $latest) = mysql_fetch_row($lstres)) {
    echo "$id $pilot $latest <br/>";
}	
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.