Jump to content

Pagination problem


Gruzin

Recommended Posts

Hi guys,
I'am having a trouble with pagination. I have a search script, which works ok and now I want to add some pagination to it... so here is my error:
[code]Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /users/3d_cn~1/html/se/search.php on line 86[/code]

Thanks for your time,
And here is the interesting part of the code:

[code]<?php
require("config.php");

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Define the number of results per page
$max_results = 1;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results); 

$query =
"SELECT *  FROM `Mater` WHERE `MatName` LIKE '%$trimmed%'
UNION
SELECT *  FROM `Mater` WHERE `MatNameE` LIKE '%$trimmed%'
UNION
SELECT *  FROM `Mater` WHERE `MatNameR` LIKE '%$trimmed%' ORDER BY `MatName` ASC LIMIT $from,$max_results";

$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result); //number of matching rows

echo "<span class='header'>$num $echo</span>"; // show the number of matching results before loop
echo "<br>";
echo "<a href='javascript:history.back()'> $back </a>";


if($num > 0){    //at least one match
while($row = mysql_fetch_assoc($result)){ //to loop through all of the matches
//--- start the result echo
if($lang == "Georgian"){
$res = $row['MatName'];
}
elseif($lang == "Russian"){
$res = $row['MatNameR'];
}
else{
$res = $row['MatNameE'];
}
echo "<p>";
echo $res;
echo "<p>";
//------- end results
}
  }
  else{
  echo '<p>';
  echo "<a href='javascript:history.back()'> $back </a>";
  }

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM MatName"),0);
// Figure out the total number of pages
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page <br />";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> ";
}

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

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>";
}
echo "</center>";
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/28660-pagination-problem/
Share on other sites

Archived

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

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