scipt for pagination
Posted: Tue Feb 22, 2005 11:17 pm
hi there
just wanna share some script for paginatioin, i spent 2 days searching for the right one fit for a newbie like me, i found it last night somewhere in the net, can't remember the site...
anyway, i modified some codes.simple, yet i'm satisfied, and i think its the code is messy...for a newbie looking for a nice script, this might help.
good day!
pleigh
just wanna share some script for paginatioin, i spent 2 days searching for the right one fit for a newbie like me, i found it last night somewhere in the net, can't remember the site...
anyway, i modified some codes.simple, yet i'm satisfied, and i think its the code is messy...for a newbie looking for a nice script, this might help.
Code: Select all
if ($rowї0])
{
if(isset($_GETї"p"]))
{
$p = intval($_GETї"p"]);
}
else
{
$p = 1;
}
$limit = 10;
$limitvalue = ($p * $limit - ($limit));
$result_count = mysql_query("SELECT count(*)as vv FROM posts");
$myrow=mysql_fetch_array($result_count);
$totalrows = $myrowї"vv"];
$result = mysql_query("SELECT DATE_FORMAT(date, '%M %D, %Y'), title, postID, firstname FROM posts AS p, users AS u
WHERE p.userID = u.userID ORDER BY date DESC LIMIT $limitvalue, $limit") or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0)
{
echo("Nothing to Display!");
}
echo "<tr align=center><td width=20%><table><tr><td><b>NAME</b></td></tr></table></td>
<td width=60%><table><tr><td><b>TOPIC</b></td></tr></table></td>
<td width=20%><table><tr><td><b>DATE</b></td></tr></table></td></tr>";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<tr><td width=20%><table><tr><td><b><a href="" class="under">$rowї3]</a><b></td></tr></table></td>
<td width=60%><table><tr><td><a href="reportview.php?pid={$rowї2]}" class="under">$rowї1]</a></td></tr></table></td>
<td width=20%><table><tr><td>$rowї0]</td></tr></table></td></tr>";
}
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
echo '<tr>';
echo '<td width="50%" align="left">';
echo "page no. $p<br>";
echo '</td>';
echo '<td width="50%" align="right">';
if($p == 1)
{
NULL;
}
else
{
$pageprev = $p-1;
echo("<a href="report.php?p=$pageprev" class=under>PREVIOUS</a> ");
}
$numofpages = ($totalrows / $limit) + 1;
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $p)
{
echo($i." ");
}
else
{
echo("<a href="report.php?p=$i" class=under>$i</a> ");
}
}
if(($totalrows - ($limit * $p)) > 0)
{
$pagenext = $p+1;
echo("<a href="report.php?p=$pagenext" class=under>NEXT</a>");
}
else
{
NULL;
}
echo '</td>';
echo '</tr>';
echo '</table>';
mysql_free_result($result);
}
else
{
echo 'system error!<br>'.mysql_error();
}
mysql_close();pleigh