The code as it appears on the web page is listed below, it is not complete as I am having problems towards the end, basically I create a Temp table place corresponding records from two existing tables into it (seedtmp1)
I then create a second temporary table and filter the first one so that all records greater than 4 months old are ignored.
What I then need to do but am having problems is take the latest 3 records for each team and place them in another temporary table (seedtmp3) What I can not do is seem to incorporate the while statement to "iterate" the query so it fills seedtmp3 with the latest 3 records for each team.
Any help in the right direction is greatly appreciated.
Nigel.
<?
$db = mysql_connect("Server", "User", "Password"
mysql_select_db("Database", $db);
$query = "DROP TABLE IF EXISTS seedtmp1";
$query = "CREATE TEMPORARY TABLE seedtmp1";
$query = "SELECT Ttimes.TRN, Teams.Team, Ttimes.Fastest_Time, Venues.Date, Venues.Venue
FROM Teams
LEFT JOIN Ttimes ON Teams.TRN = Ttimes.TRN
LEFT JOIN Venues ON Ttimes.Tournament_ID = Venues.Tournament_ID ";
$query = "CREATE TEMPORARY TABLE seedtmp2";
$query = "SELECT TRN, Team, Fastest_Time, Date, Venue
FROM seedtmp1
WHERE Date>DATE_SUB(CURDATE(), INTERVAL 120 DAY)
ORDER BY Date DESC";
$query1 = "Select TRN from seedtmp2";
$result = mysql_query($query, $db);
$phtres = mysql_query($query1, $db);
$query2 = "CREATE TEMPORARY TABLE seedtmp3";
$query2 = "SELECT TRN, Team, Fastest_Time, Date, Venue
FROM seedtmp2
WHERE TRN = '$rst'
Order by Date DESC LIMIT 3";
$rst = mysql_fetch_array($phtres);
$result1 = mysql_query($query2, $db);
?>
I then create a second temporary table and filter the first one so that all records greater than 4 months old are ignored.
What I then need to do but am having problems is take the latest 3 records for each team and place them in another temporary table (seedtmp3) What I can not do is seem to incorporate the while statement to "iterate" the query so it fills seedtmp3 with the latest 3 records for each team.
Any help in the right direction is greatly appreciated.
Nigel.
<?
$db = mysql_connect("Server", "User", "Password"
mysql_select_db("Database", $db);
$query = "DROP TABLE IF EXISTS seedtmp1";
$query = "CREATE TEMPORARY TABLE seedtmp1";
$query = "SELECT Ttimes.TRN, Teams.Team, Ttimes.Fastest_Time, Venues.Date, Venues.Venue
FROM Teams
LEFT JOIN Ttimes ON Teams.TRN = Ttimes.TRN
LEFT JOIN Venues ON Ttimes.Tournament_ID = Venues.Tournament_ID ";
$query = "CREATE TEMPORARY TABLE seedtmp2";
$query = "SELECT TRN, Team, Fastest_Time, Date, Venue
FROM seedtmp1
WHERE Date>DATE_SUB(CURDATE(), INTERVAL 120 DAY)
ORDER BY Date DESC";
$query1 = "Select TRN from seedtmp2";
$result = mysql_query($query, $db);
$phtres = mysql_query($query1, $db);
$query2 = "CREATE TEMPORARY TABLE seedtmp3";
$query2 = "SELECT TRN, Team, Fastest_Time, Date, Venue
FROM seedtmp2
WHERE TRN = '$rst'
Order by Date DESC LIMIT 3";
$rst = mysql_fetch_array($phtres);
$result1 = mysql_query($query2, $db);
?>