PDA

View Full Version : having numbered pages


Kenzo
08-14-2006, 12:20 PM
im trying to have numbered pages in my results page, but for some reason i keep getting the mysql_fetch_array(): error message, i dont know what im doing wrong, any ideas, the code is below.....




<?

// mumber of pages to be displayed....

$display = 10;

//how many Pages Kenzo?

if (isset($_GET['np']))
{

$num_pages = $_GET['np'];
}

else

{
// count this s.....

$query = " SELECT COUNT (*) FROM tablex ORDER BY id ASC";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];


}


// how many pages?

if ($num > $display)
{
$num_pages = ceil ($num_records/$display);
}
else
{
$num_pages = 1;
}





// check

if (isset($_GET['s']))
{
$start = $_GET['s'];
}
else
{
$start = 0;
}



// catch location
$location = $_POST['cmp'] ;
$category = $_POST['cat'] ;



$query = mysql_query("
SELECT *
FROM
tablex
WHERE
location = '$location' AND
category = '$category'
ORDER BY
id
ASC
LIMIT $start, $display
",$db);
}


$num = mysql_num_rows($query);



// number of comapnies check.......
if ($num > 0) {
echo "<span class='redno'> $num $category</span> in <span class='redno'> $location </span> displayed........<br><br>";
}
else
{
echo "Search returned no companies....Sorry.";
}
?>



<br><br>





<?



// print companies and duplicate rows......
while ($row = mysql_fetch_array($query)) {


echo "<div class='rsbar'></div><br><table class='phptable'><tr><td><span class='mheader'>COMPANY NAME :</span></td><td>" . $row['companyname'] . " </td></tr><tr><td><span class='mheader'>LOCATION :</span></td><td>" . $row['location'] . "</td></tr><tr><td><span class='mheader'>NATURE OF BUSINESS :</span></td><td>" . $row['category'] . "</td></tr><tr><td><span class='mheader'></span></td><td> <a href='../login_pass.php'>Contact Details</a></td></tr></table><br>";



}

mysql_close();




// Make Links........

if ($num_pages > 1)
{
echo "<br>";

$current_page = ($start/$display) + 1;


// make previous button

if ($current_page != 1)
{
echo "<a href='catcmpresults.php?s=" . ($start - $display) . "&np=" . $num_pages . "'> Previous </a>";

}





// make numbered pages

for ($i = 1; $i <= $num_pages; $i++)
{
if ($i != $current_page)
{
echo "<a href='catcmpresults.php?s=" . (($display * ($i - 1))) . "&np=" . $num_pages . "'>" . $i . "</a>";

}
else
{
echo $i . " ";
}

}


// make next button

if ($current_page != $num_pages)
{
echo "<a href='catcmpresults.php?s=" . ($start - $display) . "&np=" . $num_pages . "'> Previous </a>";

}

echo "<br>";

}

?>