Jump to content

Archived

This topic is now archived and is closed to further replies.

kenzo

having numbered pages

Recommended Posts

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.....


[code=php:0]

<?

// 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>";

}

?>


[/code]

Share this post


Link to post
Share on other sites
change $result = mysql_query ($query);

for

$result = mysql_query ($query) or die("Failed with the following error: ".mysql_error());


And paste back the error :)

Regards
Liam

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.