Jump to content

having numbered pages


kenzo

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.