View Full Version : db results paging

04-30-2006, 05:18 PM
Ok i realy need to know why my search is not working correctly lol.....well it works it brings results but does not display pages..

the limit is 5 so it displays only 5 results...(i dont have much in db but i have more then 5 items)

Ok heres the code:

$searchin = $_GET[searchlink];

$page = 1;
} else {
$page = $_GET['page'];
$max_results = 5;
$from = (($page * $max_results) - $max_results);


$query="SELECT linkname, linkdes,
url FROM indexedlinks WHERE linkname LIKE '%$searchin%' LIMIT $from, $max_results";

$result=mysql_query($query); //already tryed .mysql_error() on all

while($srows=mysql_fetch_array($result)) {

$name = $srows[linkname];
$linkdisc = $srows[linkdes];
$url = $srows[linkurl];

echo "<table width=\"100%\" bgcolor=\"#ffffff\" cellspacing=\"2\" cellpadding=\"2\" border=\"1\">

echo "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Site Name:</font></td>
<td align=\"left\"> ";

echo $sitename;

echo "</td></tr><tr>";

echo "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Site Discription:</font></td>
<td align=\"left\"> ";

echo $linkdisc;

echo "</td></tr><tr>";

echo "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Url:</font></td><td align=\"left\"> ";

echo "<a href=\"$url\" target=_blank\">$url</a>";

echo "</td></tr>";

echo "</table> <br><br>";

$total_results ="SELECT COUNT(*) as Num FROM thelinks";

$reso=mysql_query($total_results) or die(mysql_error());

$total_pages = ceil($total_results / $max_results);

echo "<center>Select a Page<br>";

if($page > 1){
$prev = ($page - 1);
echo "<a href=\"?page=$prev\"><<Previous</a> ";

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"?page=$i\">$i</a> ";

if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"?page=$next\">Next>></a>";
echo "</center>";

05-01-2006, 11:01 AM
I'm guessing that it's having problems with this:

$total_pages = ceil($total_results / $max_results);

You're trying to divide a string by a number. $total_results is your SQL string.

05-01-2006, 01:11 PM
Put some echo statements in strategic places in your code, so that you can see what the values are for your variables at each step of the way. When your expected and actual values differ, then you have pinpointed a problem with your code.