Hi folks
Im having a problem trying to retrieve data from my mysql table.
I would like to retrieve the last record in my database table but only the last record.
| SitePoint Sponsor |

Hi folks
Im having a problem trying to retrieve data from my mysql table.
I would like to retrieve the last record in my database table but only the last record.


do you have an auto increment field? if so order by that....
(bit cryptic I know but you haven't given me much to work with!)
You could also use mysql_insert_id and last_insert...
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!




Do you have an id column?
Sigh ... I keep getting beaten to the post. Must type faster![]()
Last edited by MikeBigg; Jan 4, 2005 at 10:41. Reason: Late post

Ah sorry guys should have explained better.
right this is the code i have so far
It works fine untill someone tryed to go back on the first image ( which i want to send them to the last image in the database ) it sends them to the wrong picture because there are 142 records but the last image id is 144 because some where deleted.PHP Code:$test = mysql_query( "SELECT photo_id FROM gallery_photos");
$nr = mysql_num_rows( $test );
$prevphoto = $pid - 1;
$nextphoto = $pid + 1;
if ($nextphoto > $nr) {
$nextphoto = 1;
}
if ($prevphoto < 1) {
$prevphoto = $nr;
}
$result_final .= "<tr>\n\t<td>
<a href='viewgallery.php'>Categories</a> >
<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n";
$result_final .= "<td align='center'>
<a href='viewgallery.php?cid=1&pid=$prevphoto'>Previous Photo</a> <>
<a href='viewgallery.php?cid=1&pid=$nextphoto'>Next Photo</a>$row</td>\n</tr>\n";
I hope you can understand that.
Bookmarks