Hey everyone,
I have a table listing pictures, what gallery they are in and what order they should be displayed in. To find the previous and next pictures from the picture page i am using the min and max mysql functions on the order field (as long as it's above or below the current order value). I think i'm being really thick, but i can't quite work out why it works when you're trying to find the next pic using this code:
$queryn = "SELECT FName, MIN(FOrder) FROM TPictures2 WHERE FGallery='$gid' AND FOrder>'$order' GROUP BY FGallery";
echo $queryn.'<br>';
$resultn = mysql_query($queryn);
$totaln = mysql_numrows($resultn);
if($totaln>0)
{
$next=1;
$nextt=mysql_result($resultn,0,"MIN(FOrder)");
$nextname=mysql_result($resultn,0,"FName");
echo 'NEXT ORDER: '.$nextt.'<Br>';
echo 'NEXT PIC: '.$nextname.'<Br>';
}
however when i do the reverse and try and find the previous pic it always returns MAX(FOrder) correctly, but returns the FName of the first record in the table, which is not the one with that MAX(FOrder):
$queryp = "SELECT Fid, FName, MAX(FOrder) FROM TPictures2 WHERE FGallery='$gid' AND FOrder<'$order' GROUP BY FGallery";
echo $queryp.'<br>';
$resultp = mysql_query($queryp);
$totalp = mysql_numrows($resultp);
if($totalp>0)
{
$prev=1;
$prevt=mysql_result($resultp,0,"MAX(FOrder)");
$prevname=mysql_result($resultp,0,"FName");
echo 'PREV ORDER: '.$prevt.'<Br>';
echo 'PREV PIC: '.$prevname.'<Br>';
}
As i say i think i'm just doing something really stupid, but i can't see the wood for the trees! Any help would be very much appreciated.
Thanks very much everyone,
Dave