Forum Moderators: coopster
Here is the example, results on letter A, maximum results 10, sorted alphabetically (NON-WORKING EXAMPLE):
I hope that someone knows how to do it on php...
Please help me!
Thanks in advance!
[edited by: jatar_k at 11:27 pm (utc) on May 27, 2006]
[edit reason] no urls thanks [/edit]
You can just ORDER BY name to get alphabetical order. Per page would be something like:
$page = (isset($_GET['page'])? $_GET['page'] : 1);
$limit = $page * 30 - (30);mysql_query("SELECT * FROM table ORDER BY name LIMIT $limit,30");
Then for pagination:
index.php?page=1 //Page 1
index.php?page=2 //Page 2
etc
dc
So for example it will go like index.php?letter=A&page=2
And that it will generate me the links to pages automatically?
[edited by: jatar_k at 11:28 pm (utc) on May 27, 2006]
[edit reason] no urls thanks [/edit]
To auto generate your page numbers, something like this should work ok:
// Firstly, get the total number of rows..
$query = mysql_query("SELECT count(*) as page_count FROM table") or die(mysql_error());
$row = mysql_fetch_object($query);// Then loop something like this..
$numofpages = $row->page_count/30;for ($i=1; $i<=$numofpages; $i++)
{
if ($i == $page)
{
echo '<b>'.$i.'</b> ';
}
else
{
echo '[<a href="index.php?page='.$i.'">'.$i.'</a>]';
}
}// Loop for remainder if above calculation was not an integer..
if ($row->page_count % 30!= 0)
{
if ($i == $page)
{
echo '<b>'.$i.'</b> ';
}
else
{
echo '[<a href="index.php?page='.$i.'">'.$i.'</a>]';
}
}
Think that should be ok.
dc