I have the feeling that some parts of the next code are not particulaire well written or thought out.
Specialy where I calculate the total # of records.
Can you help me make this better code?
I have not tested it yet, but it demonstrates the general idea. No garantees it will work as is.
Specialy where I calculate the total # of records.
Can you help me make this better code?
I have not tested it yet, but it demonstrates the general idea. No garantees it will work as is.
Code:
<?php
import_request_variables("GP");
$records_per_page=50;
if (!$pag)
{$limit=" limit " . $records_per_page;}
else
{$limit=" limit " . ($page * $records_per_page) . "," . $records_per_page;}
$query="SELECT * FROM `table` WHERE `forum`='$forum' ";
$result=mysql_query($query);
$total=msql_num_rows($result) ;
$pages=ceil($total / $records_per_page);
$query="SELECT * FROM `table` WHERE `forum`='$forum' " . $limit;
$result=mysql_query($query);
while($line=mysql_fetch_array($result,MYSQL_ASSOC))
{
/* list entries */
}
if ($total>$records_per_page) {
for ($i=1;$i<$pages;$i++) {
print "<a href='thisfile.php?forum=$forum&pag=$i'>-$i-</a> "; }}
?>