I'm so sorry jppp.
My mistake with my coding. 
Don't worry though I've sorted it out and even tested it. 
I did try your code and I must say it's a bit messy, never mind you will learn, I'm still learning even at this stage. 
Anyway, the coding error was to do with the 'while' listing, I got the Next and Previous the wrong way round.
The code below has the next and previous links working.
PHP Code:
<pre>
<?php
include('config.inc.php');
$id = '6520';
$everything = array();
$all = mysql_query("SELECT min(photo_id) AS First
, min(photo_caption) AS Cap
, min(photo_filename) AS File
, min(photo_category) AS Cate
, ( SELECT max(photo_id)
FROM gallery_photos
WHERE photo_id < '".$id."' ) as Prev
, ( SELECT min(photo_id)
FROM gallery_photos
WHERE photo_id > '".$id."' ) as Next
FROM gallery_photos
WHERE photo_id = '".$id."'
ORDER BY photo_id ASC");
while($list = mysql_fetch_array( $all )) {
$everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list['Cate'], 'next' => $list['Next'], 'prev' => $list['Prev']);
}
mysql_free_result( $all );
echo ' <table width="490" border="0" cellpadding="0" cellspacing="0">';
echo ' <tr>';
foreach($everything as $s => $sval) {
echo ' <td><div align="left">This ID: '.$sval['now'].'</div>';
echo ' <div align="left">The Filename: '.$sval['file'].'</div>';
echo ' <div align="left">Its Caption: '.$sval['caption'].'</div>';
echo ' <div align="left">Which Category: '.$sval['category'].'</div>';
echo ' <div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
echo ' <div align="left">Previous: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['prev'].'">'.$sval['prev'].'</a></div></td>';
}
echo ' </tr>';
echo '</table>';
echo "\n";
print_r($everything);
?>
</pre>
Near the beginning I've used the id 6520, one of my own for testing, this should be deleted and then add your own code. Also, if there's no other photo before or after the one displayed the link will not be shown.
So you will need to do something like this to make sure the Next or Prev is not displayed:
PHP Code:
// if next is set display link
if(isset($sval['next'])) {
$next = '<div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
}
echo $next;
Here's the full code:
PHP Code:
<pre>
<?php
include('config.inc.php');
$id = '6520';
$everything = array();
$all = mysql_query("SELECT min(photo_id) AS First
, min(photo_caption) AS Cap
, min(photo_filename) AS File
, min(photo_category) AS Cate
, ( SELECT max(photo_id)
FROM gallery_photos
WHERE photo_id < '".$id."' ) as Prev
, ( SELECT min(photo_id)
FROM gallery_photos
WHERE photo_id > '".$id."' ) as Next
FROM gallery_photos
WHERE photo_id = '".$id."'
ORDER BY photo_id ASC");
while($list = mysql_fetch_array( $all )) {
$everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list['Cate'], 'next' => $list['Next'], 'prev' => $list['Prev']);
}
mysql_free_result( $all );
echo ' <table width="490" border="0" cellpadding="0" cellspacing="0">';
echo ' <tr>';
foreach($everything as $s => $sval) {
// if next is set display link
if(isset($sval['next'])) {
$next = '<div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
}
// if prev is set display link
if(isset($sval['prev'])) {
$prev = '<div align="left">Prev: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['prev'].'">'.$sval['prev'].'</a></div>';
}
echo ' <td><div align="left">This ID: '.$sval['now'].'</div>';
echo ' <div align="left">The Filename: '.$sval['file'].'</div>';
echo ' <div align="left">Its Caption: '.$sval['caption'].'</div>';
echo ' <div align="left">Which Category: '.$sval['category'].'</div>';
echo $next;
echo $prev;
}
echo ' </tr>';
echo '</table>';
echo "\n";
print_r($everything);
?>
</pre>
spence
Bookmarks