Okay, here is my code for displaying 10 items out of a database, and also creating "Next/Prev" buttons. I have removed some stuff as it doesn't apply, but have tried to add a comment saying what was there:
// Below recives variable disp from URL, if it exsists it assings it to $disp_min, if not it sets it to the first page/0
if($_GET[disp] == null) {
$disp_min = 0;
} else {
$disp_min = $_GET[disp];
}
//Connect to database, create a table...that stuff was here, but removed.
//Then we find how many items are in the database
$MQuery = "select count(ID) from DATABASE";
$result = mysql_query($MQuery);
$num_rows = mysql_fetch_array($result);
//We got the minimum ID number from the $_GET[disp], since this version we can't select results per page, we just add 10 to get the max ID number
$page_max = $page + 10;
//Running a query only gettings the items where the ID is between are paramaters. The ID row is a BIGINT primary key in MySQL
$MQuery = "SELECT * FROM PicsDB
ID>='$disp_min' AND ID<='$disp_max'
ORDER BY Desc ID"
$mysqlout = mysql_query($MQuery);
//Checking for how many rows where returned, just in case something happend, or in the future we allow the user to select results per page.
$rows_returned = mysql_num_rows($result);
for($inc=1; $inc <= $rows_returned; $inc++) {
$result = mysql_fetch_array($mysqlout);
//In here we process the results.
}
//Now we begin creating the next previous buttons, and the number that go in between them First we find out how many pages we have.
$pages = intval($num_rows/10);
//Adjust for a remainder
if ($num_rows % 10) {
$pages++;
}
//Find our current page
$current_page = intval($disp/10 + 1);
//Create <<< Prev button if required.
if($current_page != 1 AND $disp != 1){
$prev_page = $disp_min - 10;
print("<IMG SRC=\"admin.php?page=dispphoto&disp=$prev_page\"><<< Prev</A>");
}
//Now we begin creating the numbers in between
for($inc=1; $inc < $pages; $inc++){
//Since the script works on ID numbers, not pages we find the new ranges, this gives us our max
$page_disp = $inc * 10;
//We want the minimum range to pass to the script
$page_disp = $page_disp - 10;
//Just checking to see if it is the current page or not.
if($page_disp == $disp_min) {
print("$inc");
} else {
//Add Create link
print("<IMG SRC=\"admin.php?page=dispphoto&disp=$page_disp\">$inc</A>");
}
}
//Create Next >>> Button, but first me must make sure we arn't on the last page.
if($disp_max < $num_rows){
$page_disp = $pages * 10;
$page_disp = $page_disp - 10;
print("<IMG SRC=\"admin.php?page=dispphoto&disp=$page_disp\">Next >>></A>");
}
//Close tables, .etc
Okay, now here are my questions.
1)Lets say a row gets removed with the ID of say, 7 will MySQL adjust the numbers in the auto_increment row or will it leave it behind, so in reality if I get all ID's within the range of 0-10 I will only get 9 items. If that is true what is the best way to recount the ID rows when an item is deleted, do I have to go one by one and adjust them or do Is there some "recount" feature in MySQL I can take advantage of?
2)As you can see now, the user can't select the number of rows he/she wants displayed the reason I didn't do this was because I want the user to be able to change it on the page, but is there a way to pass this along to the script ussing the links generated (1,2,3,4 .etc) as form submit buttons, or do I have to do this within a seperate form?
3)Any other problems I might not have forseen??
TIA, Bryce