I am currently developing a pagination script. The following code is what I have so far, but for some reason, the code in bold throws up errors. Why is this?
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$perpage = 2;
$start = (isset($GET['id'])) ? $GET['id'] : 0;
$TotalRec = mysql_result(mysql_query("SELECT COUNT(*) FROM person"), 0);
$select = "SELECT * FROM person LIMIT $start, $perpage";
$result = mysql_query($select) or die(mysql_error());
Dislay your rows here in the loop
while($row = mysql_fetch_array($result))
{
echo $row['name']." ";
echo $row['age']." ";
echo $row['sex'].'<br />';
}
if($start == 0)
{
echo "PREVIOUS";
}
else
{
echo '<a href=\"./display.php?id="' . ($start - $perpage) . '"\">PREVIOUS</a>"';
}
$page = ($_GET['id'] / $perpage) + 1;
$total = ceil($TotalRec / $perpage);
if($start + $perpage >= $TotalRec)
{
echo "NEXT";
}
else
{
echo '<a href=\"./display.php?id="' . ($start + $perpage) . '"\">NEXT</a>';
}
echo '</div>';
?>