Click to See Complete Forum and Search --> : PHP - restriction on number of records per page


tony2222
01-25-2001, 09:57 AM
Hello,

My problem is:
I have a table with 20 records.
I want to make a script which will make a html page for each 5 records per page.

So I want to be able to restrict the number of records on the page

Thanks.

nanode
01-25-2001, 11:38 AM
I did exactly that:


function showUpdates($numRows, $bg, $altbg, $font, $altfont) {
$sql = "SELECT * FROM updateitems ORDER BY id DESC";
if($numRows > 0) { $sql = $sql . " LIMIT " . $numRows; }

mysql_pconnect(localhost,root);
$rs = mysql_db_query("websitedb", $sql);

$rc = 0;
$x = 1;
$topID = 0;

echo "<table border=0 cellspacing=0 cellpadding=0 width=15% bgcolor=#000000 align=left><tr><td>";
echo "<TABLE border=0 cellspacing=0 cellpadding=3 width=100% bgcolor=#000000>";

echo "<TR><TD bgcolor=$bg colspan=2 align=center>";
echo "<FONT face=arial color=$font size=2>News and Updates</FONT>";
echo "</TD></TR></TABLE>";
echo "<TABLE border=0 cellspacing=0 cellpadding=3 width=100% bgcolor=#000000>";

while ($row = mysql_fetch_object($rs)) {
if($x == 1) {
$tableColor=$altbg;
}
else {
$tableColor=$bg;
}

$id = $row->id;
$title = $row->title;
$date = $row->releasedate;
echo "<TR bgcolor=$tableColor><TD width=50%>
<FONT face=arial color=#000000 size=1>
<a href=\"index.php?id=$id\" style=\"text-decoration: none\">
$title</a></FONT></TD><TD width=50%><FONT face=arial color=#000000 size=1>
$date</FONT></TD></TR>";

$x = $x * -1;
$rc++;
if($rc == 1) {
$topID = $id;
}
}

echo "</TD></TR></TABLE>";
echo "<TR><TD bgcolor=$altbg colspan=2 align=center>";
echo "<FONT face=arial color=$font size=2>
<A HREF=\"index.php?show=-1\" style=\"text-decoration: none\">Show All Entries</A></FONT>";

echo "</TD></TR></TABLE>";
echo "</TD></TR></TABLE>";

return $topID;
}


The arg $numRows indicates how many rows to display, if 0 show all. So I can reuse this function for when we DO want to display all records.

The complete source is at: http://yunt.net/index.phps
and the actual page: http://yunt.net

Have fun.