hello,
i have a paging section in my website. everything works fine except one problem. the problem is that if there are multiple pages there is one row missing except at the last page. the last page is missing two rows.
weird huh?
any help would be greatly appreciated...
here is the code that i use for paging through results.
sql query:
If (!isset($_GET["start"])){
$start = 1;
$page = 1;
} else {
$start = $_GET["start"];
$page = (($start-1)*10)+1;
}
$sql = "SELECT * FROM Textile WHERE MATCH(Class) AGAINST('$class')";
$result = mysql_query($sql, $db) or die (mysql_error());
$row = mysql_fetch_array($result);
$n = mysql_num_rows($result);
$sql = "SELECT * FROM Textile WHERE MATCH(Class) AGAINST('$class') LIMIT $page,10";
$result = mysql_query($sql, $db) or die (mysql_error());
$row = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
here is the part that i publish the results
<?php
while ($row = mysql_fetch_array($result))
{
echo "<font color='#800000'><a href='company.php?id=" . $row['id'] . "'><b>" . strtoupper($row['CompanyName']) . "</b></a>" . " " . "<font color='#000080'>" . "-" . "</font>" . " " . $row['CompanyType'] . "</font><br>";
echo "<font color='#800000'>Products:</font>" . " " . strtolower($row['Products']) . "<br>";
echo "<font color='#800000'>Introduction:</font>" . " " . $row['Introduction'] . "<br>";
echo "<hr>";
}
?>
and here is my prev and next links
<?php
$a = ceil($n/10);
If($start != 1){
$prev = $start-1;
echo "<a href='list.php?class=" . $class . "&start=" . $prev . "'>" . "Prev" . "</a>" . " ";
} else {
echo "Prev ";
}
for ($i=1; $i<=$a; $i++){
If ($i != $start){
echo "<a href='list.php?class=" . $class . "&start=" . $i . "'>" . $i . "</a>" . " ";
} else {
echo "<font color='#800000'><b>" . $i . "</b></font>" . " ";
}
}
If($start != $a){
$next = $start+1;
echo "<a href='list.php?class=" . $class . "&start=" . $next . "'>" . "Next" . "</a>" . " ";
} else {
echo "Next ";
}
?>
btw: i tried to set $page variable like 0, 10, 20 ... but no luck. the only remedy i had was displaying 11 results so i got 10 results but that was not what i was looking for.