Actually, I'm a newbie here...
[56K WARN] Table with previous 1,2,3 next function...
Moderator: General Moderators
[56K WARN] Table with previous 1,2,3 next function...
I have problem in doing table with function above, so i'm so afraid i can't do it.. so perhaps any of you can help me to find out this function for me..
Actually, I'm a newbie here...
Actually, I'm a newbie here...
search this forum for "pagination" or "paging"
or try http://www.google.com/search?&q=php+pagination
or try sourceforge.net, hotscripts.com
or try http://www.google.com/search?&q=php+pagination
or try sourceforge.net, hotscripts.com
Last edited by djot on Wed Jun 29, 2005 6:03 am, edited 1 time in total.
basically you'll need to set a variable for how many you'd like per page
find the total number of rows your query retrives, divide by the variable (this will give you total number of pages)
then loop through till you reach that number, something like
That's it basically. However there are some very nice pre-made pagination scripts already made if you google it.
find the total number of rows your query retrives, divide by the variable (this will give you total number of pages)
then loop through till you reach that number, something like
Code: Select all
for($i = 1; $i < $totalpages; $i++)
{
echo "<a href=\"page.php?page=$i\">$i</a> ";
}you can dieasily dissect this code and revise it to fit your needs....i hope this will help...
Code: Select all
function adminpagination()
{
//start of pagination
$display = 10;
if (isset($_GET['np']))
{
$num_pages = $_GET['np'];
}
else
{
$query = "SELECT * FROM posts";
$query_result = mysql_query ($query);
$num_records = @mysql_num_rows ($query_result);
if ($num_records > $display)
{
$num_pages = ceil ($num_records/$display);
}
else
{
$num_pages = 1;
}
}
if (isset($_GET['s']))
{
$start = $_GET['s'];
}
else
{
$start = 0;
}
// Make the query.
$query = "SELECT DATE_FORMAT(postupdate, '%M %e, %Y - %l:%i %p'), topic, postID, firstname FROM posts AS p, users AS u
WHERE p.userID = u.userID ORDER BY postupdate DESC LIMIT $start, $display";
$result = @mysql_query ($query);
$num = mysql_num_rows ($result);
if ($num > 0)
{
if ($num_pages > 1)
{
$current_page = ($start/$display) + 1;
echo '<table border=0 cellpadding=2 cellspacing=0 bordercolor=#ffffff><tr>';
if ($current_page != 1)
{
echo '<td class=tableborder><a href="report.php?s=' . ($start - $display) .
'&np=' . $num_pages . '" class=under><b/>Previous</a></td> ';
}
for ($i = 1; $i <= $num_pages; $i++)
{
if ($i != $current_page)
{
echo '<td class=tableborder><a href="report.php?s=' . (($display * ($i - 1))) .
'&np=' . $num_pages . '" class=under><b/>' . $i . '</a></td> ';
}
else
{
echo '<td bgcolor="yellow" class=tableborder><b/>'. $i . ' </td>';
}
}
if ($current_page != $num_pages)
{
echo '<td class=tableborder><a href="report.php?s=' . ($start + $display) .
'&np=' . $num_pages . '" class=under><b/>Next</a></td>';
}
echo '</tr></table>';
}
echo "<table width=100% border=1 bordercolor=#336699 cellpadding=0 cellspacing=0 class=tablehead>
<tr align=center class=tablehead><td width=20% class=tableborder><table><tr><td><b>NAME</b></td></tr></table></td>
<td width=50% class=tableborder><table><tr><td><b>TOPIC</b></td></tr></table></td>
<td width=10% class=tableborder><table><tr><td><b>REPLIES</b></td></tr></table></td>
<td width=20% class=tableborder><table><tr><td><b>DATE</b></td></tr></table></td></tr>
</table>";
echo '<table width=100% border=1 bordercolor=#336699 cellpadding=0 cellspacing=0 class=tableborder>';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$row[0] = '<font size=1>'.$row[0].'</font>';
echo "
<tr><td width=20% class=tableborder align=center><table><tr><td><b><a href=\"\" class=\"under\">".strtolower($row[3])."</a><b></td></tr></table></td>
<td width=50% class=tableborder><table><tr><td><a href=\"reportview.php?pid={$row[2]}\" class=\"under\">$row[1]</a></td></tr></table></td>
<td width=10% class=tableborder align=center><table><tr><td>".replies($row[2])."</td></tr></table></td>
<td width=20% class=tableborder><table><tr><td>$row[0]</td></tr></table></td></tr>";
}
echo '</table>';
mysql_free_result ($result);
}
else
{
echo '<h3>There are no records to show.</h3>';
}
mysql_close();
}Here is another demo http://timvw.madoka.be/demo/person_list.php
And here's the source: http://timvw.madoka.be/programming/php/pagination.zip
And here's the source: http://timvw.madoka.be/programming/php/pagination.zip
There is a tutorial here and you can download the source with sql files also.
PHP paging
Check the advanced paging also if you have more number of records and not in a position to show all the links at a time.
http://www.plus2net.com/php_tutorial/php_paging_adv.php
PHP paging
Check the advanced paging also if you have more number of records and not in a position to show all the links at a time.
http://www.plus2net.com/php_tutorial/php_paging_adv.php
