Hi,
I've modified the code u'd given. Just go thru it.
the file name is used is testrecords.php
Before checking with the file. pls add as many records to test with. if u have less records then change the $limit to less than 10.
so that u can test it easily.
Rgds,
Kumar.S
the code
<?
//testrecords.php
$connection = mysql_connect("host", "user", "password");
mysql_select_db("felix5");
$limit=10;
$Prev = "Previous";
$Next = "Next";
//$numresults=mysql_query("SELECT * FROM artist WHERE keterangan='$id' ORDER BY id ASC");
$numresults=mysql_query("SELECT id,keterangan FROM artist ORDER BY id ASC");
$numrows=mysql_num_rows($numresults);
// if (empty($offset)) {
// $offset=0;
// }
//change the above as the following
if (isset($offset)) {
$offset=0;
}
else{
$offset=$_REQUEST['offset'];
}
echo "<table width=100% bgcolor=#FFFFFF border=0 cellpadding=2 cellspacing=1>";
$sql = "SELECT id,keterangan FROM artist ORDER BY id ASC limit $offset,$limit ";
$result = mysql_query($sql,$connection) or die("Could not execute query.");
while ($row = mysql_fetch_array($result)) {
echo "
<tr bgcolor=#C0C0C0>
<td align=center><font face=tahoma size=1 color=#000000 size=1><b>$row[id]</b></font></td>
<td><font face=tahoma size=1 color=#000000 size=1><b>$row[keterangan]</b></font></td>
</tr>
";
}
mysql_free_result($result);
echo "</table>";
$pages=intval($numrows/$limit);
$pages1=intval($numrows/$limit);
if ($pages1 > 10) {
$pages=10;
}
else {
$pages=$pages1;
}
if ($numrows%$limit) {
$pages++;
}
if ($offset>1) {
$prevoffset=$offset-$limit;
//print "<a href=\"$PHP_SELF?offset=$prevoffset\">$Prev</a> \n";
//change this line into
print "<a href=testrecords.php?offset=$prevoffset>$Prev</a> \n";
}
for ($i=1;$i<=$pages;$i++) {
$newoffset=$limit*($i-1);
//print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
//change the above into
print "<a href=testrecords.php?offset=$newoffset>$i</a> \n";
}
if ($numrows>($offset+$limit)) {
$nextoffset=$offset+$limit;
//print "<a href=\"$PHP_SELF?offset=$nextoffset\">$Next</a><p>\n";
//change the above line into
print "<a href=testrecords.php?offset=$nextoffset>$Next</a><p>\n";
//however u can use $PHP_SELF also to refer the current script
}
?>