I have a table with 58 records in mysql database. I was able to connect to my database and retrive all records and made 5 pages with links to view each pages using php script.
webpage will look like this:
name number
john 1232343456
tony 9878768544
jack 3454562345
joe 1232343456
jane 2343454567
andy 2344560987
marcy 9873459876
sean 8374623534
mark 9898787675
nancy 8374650493
1 2 3 4 5
that's the first page of 58 records and those 5 numbers at bottom are links to each page that will display next 10 records. I got all that. but what I want to do is display the links in this way:
1-10 11-20 21-30 31-40 41-50 51-58
note: since i have 58 records, last link will display upto 58, instead of 60.
Since I used the loop to create this link, depending on how many records i have, the link will change according to the number of records in my table. How can i do this?
Thanks.
EDIT: since first page is already displaying, 1-10 will not be a link. same goes for other pages. whatever page is displaying, that link will not be a link.
EDIT2: this is my code for those links
$limit=10;
if($totalrecords > $limit )
{
echo "<table align = 'center' width='50%'><tr>";
// Display the page links at center. Current page will not be a link.
echo "<td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $totalrecords;$i=$i+$limit)
{
if($i <> $current)
{
echo " <a href='$page_name?start=$i'>$l</a> ";
}
else
{
echo "$l";
}
$l=$l+1; // Current page is not displayed as link.
}
echo "</td></tr></table>";
}
in this code, each page links display as:
1 2 3 4 5