I need to select records from a database based on an id number and timestamp
I can select based on id without a problem, whare I need help is selecting only the records with the first and latest timestamp.
Example:
table 1
id-------data--------timestamp
1--------xxx---------1111
1--------xxx---------1112
1--------xxx---------1113
2--------xxx---------1111
2--------xxx---------1112
2--------xxx---------1113
I only want to display records:
1--------xxx---------1111
1--------xxx---------1113
2--------xxx---------1111
2--------xxx---------1113
My current code displays all the records:
<?php
$tableid=68;
echo "<center><strong>$tableid</strong><br><br></center>";
$query="SELECT * FROM ad_order WHERE cust_id=$tableid";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num)
{$id=mysql_result($result,$i,"id");
//////////////////////////
/////display only the first and last records of table 68
/////////////////////////
echo "<center>$id<br></center>";
$i++;}
?>