Hi there, i am hoping somebody can help me...
I am trying to expand the following pages script.
At the moment, it displays 10 results per page, and lists all of the page numbers at the bottom
However,i wish to expand it to make it so it only shows 10 pages at the bottom of the page, for the main reason that if i have (for example), 900 records, it would display 90 numbers at the base of the page (which i dont want!!).
This forum uses the same concept.
Instead, i want to list the 5 pages before, and 5 pages after the origional page. For example... if i am page 50, it would display page numbers:
45 46 47 49 49 (50) 51 52 53 54 55
Anyway here is my existing code:
===========
<?php
// Log into MySQL database
$db = mysql_connect("localhost", "xxxx", "xxxx") or die ("Could not connect");
mysql_select_db("xxxx") or die ("Could not select db");
if($page == "") {
$page = "1";
}
$limit = 10;
$sqlcount= "SELECT * FROM messages WHERE to = '$username' ORDER BY id";
$sql_countresult = mysql_query($sqlcount, $db) or die ("Couldn't execute query");
$totalrows = mysql_num_rows($sql_countresult);
if(empty($page)){
$page = 5;
}
$limitvalue1 = $page$limit-($limit);
$sql = "SELECT FROM messages WHERE to = '$username' ORDER BY id desc LIMIT $limitvalue1, $limit";
$sql_result = mysql_query($sql, $db) or die ("Couldn't execute query");
while ($row = mysql_fetch_array($sql_result)){
echo "From: <b>$row[from]</b><br> ";
echo "To: <b>$row[to]</b><br> ";
echo "Subject: <b>$row[subject]</b><br> ";
echo "Message: <b>$row[message]</b><br><br> ";
}
echo "<BR>";
if($pageprev = $page - 1) {
echo " <A HREF=\"$PHP_SELF?username=$username&page=$pageprev\"><</A>"; // if page is not equal to one, prev goes to $page - 1
}
$numofpages = $totalrows/$limit;
for($i= 1; $i < $numofpages+1; $i++) {
echo " <A HREF=\"$PHP_SELF?username=$username&page=$i\">$i</A>"; //make number navigation
}
if(($totalrows-($limit$page)) > 0){
$pagenext = $page + 1;
echo " <A HREF=\"$PHP_SELF?username=$username&page=$pagenext\">></A>"; // if the totalrows - $limit $page is > 0 (meaning there is a remainder), leave the next button.
}
mysql_free_result($sql_result);
mysql_close($db);
?>
================
I beleive its something to do with this line but im not sure:
$numofpages = $totalrows/$limit;
Any help would be great, as i have been trying for the past 2 days solid!!!
Thanks in advance....
Jonathan