First off thanks guys for your input to my problem, However I'm still dealing with two issues. In my database I purposely have a gap between my id to simulate a deleted record and interruption between the number sequence. this still causes errors when going from record 16 then the next record id is 14, mainly because its looking for record id 15 that doesn't exist.
The other issue I'm still having when I'm on the last record and hit next a error pops up because of going back to first record being displayed it looking for the next record id in the current sequence and same for when I'm on the first record being displayed and hit previous same error results.
Here is the more my actual code, its displaying images that information of the images being stored in the database.
// Get Data from database
<?
include $_SERVER['DOCUMENT_ROOT'].'/common.php';
$num_records = @mysql_query("SELECT COUNT(*) FROM gallery") or die (mysql_error());
$total = mysql_result($num_records,0,0);
$img_id = $_GET['img_id'];
$page = $_GET['page'];
$sql = mysql_query("SELECT * FROM gallery WHERE img_id= '$img_id'");
if(!$sql){
echo "Error With MySQL Query: ".mysql_error();
}
$row = mysql_fetch_assoc($sql);
stripslashes(extract($row));
?>
// html and stuff to display data information is here but not typing it all out lol.
// My next previous back links
<a href="/gallery_view.php?img_id=<?= ($img_id == 0) ? $count : $img_id - 1; ?>&page=<?=$page;?>">Next</a>
<a href="/gallery.php?page=<?=$page;?>">go back</a>
<a href="gallery_view.php?img_id=<?= ($img_id == $total) ? 0 : $img_id + 1; ?>&page=<?=$page;?>">Previous</a>
- // Get Data from database
- <?
- include $_SERVER['DOCUMENT_ROOT'].'/common.php';
- $num_records = @mysql_query("SELECT COUNT(*) FROM gallery") or die (mysql_error());
- $total = mysql_result($num_records,0,0);
- $img_id = $_GET['img_id'];
- $page = $_GET['page'];
- $sql = mysql_query("SELECT * FROM gallery WHERE img_id= '$img_id'");
- if(!$sql){
- echo "Error With MySQL Query: ".mysql_error();
- }
- $row = mysql_fetch_assoc($sql);
- stripslashes(extract($row));
- ?>
- // html and stuff to display data information is here but not typing it all out lol.
-
- // My next previous back links
- <a href="/gallery_view.php?img_id=<?= ($img_id == 0) ? $count : $img_id - 1; ?>&page=<?=$page;?>">Next</a>
- <a href="/gallery.php?page=<?=$page;?>">go back</a>
- <a href="gallery_view.php?img_id=<?= ($img_id == $total) ? 0 : $img_id + 1; ?>&page=<?=$page;?>">Previous</a>
I reversed the code of UPSGUY as you can see because my images are being displayed in descending order (from last record to first) thats the only modification I made to his.
I tried casablanca's use Limit to handled deleted records and go errors still basically saying undefined variables of the elements of the array its trying to fetch.
Not sure if there is any other soultions or something else you can see to help but if so please post.
Thanks again for your help, its gotten me of in the right direction