Jump to content

Pagination - help :D


mike_tw

Recommended Posts

I have a search.htm form with two drop downs. These drop downs post to the php page variables $Manufacturer and $colour.

 

I have had alto of trouble with this as ive only just began with php but im learning.

 

My problem is, when i click on page 2 or page 3 or whatever, it just brins back the same 25 records. I dont even think it changes page as the number 1 in the navigation is blacked out. But the url changes to say paeg=2 etc.

 

Can anyone take a look at my code and see where im going wrong?

 

The pagination links are there, it calculates how many pages it needs fine but when i click on the link it changes the url fine but displays the same 25 records and accoridng to the navigation im still on page 1.

 

I think the query may be wrong? How can i tell it to brin back recrods 25-50 on page 2?

 

Thanks for any help

 

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");

session_start();	
session_register ("Color");	
session_register ("Manufacturer");
session_register ("brick");	


$_POST['Manufacturer'] = $_SESSION['Manufacturer'];
$_POST['Color'] = $_SESSION['Color'];
$_POST['brick'] = $_SESSION['brick'];

function secured($val)
{
  $val = strip_tags(trim(($val))) ;
  $val = escapeshellcmd($val);
  return stripslashes($val);
  }
   if (get_magic_quotes_gpc()) {
$Manufacturer = $_SESSION["Manufacturer"]; 
$Color = $_SESSION["Color"]; 

} else {
$Manufacturer = addslashes($_SESSION["Manufacturer"]);
$Color = addslashes($_SESSION["Color"]); 

}
if(isset($_SESSION['brick']))  {
$where = "";
$sep = " WHERE ";
}
if($Manufacturer != "SelectManufacturer") {
$where .= $sep." Manufacturer = '".$Manufacturer."'";

$sep = " AND ";
}

if($Color != "SelectColor") {
$where .= $sep." colour = '".$Color."'";
$sep = " AND ";
}

$limit          = 25;               

if(empty($page)){
        $page = 1;
    }
$limitvalue = $page * $limit - ($limit);     
$query = "SELECT * FROM bricks $where LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Failed2: ".mysql_error());
$query1 = "SELECT * FROM bricks $where";
$result1 = mysql_query($query1) or die("Failed1: ".mysql_error());
$totalrows = mysql_num_rows($result1);
       
       if(!$totalrows)
        {
            echo "<table align='center'><tr><td align='center'>Sorry, no bricks matching your selection were found. </td></tr></table>"; //message for when no bricks are returned
         }
         else
             {         
		 echo "<table align='center' border=0 ><tr>";
                        echo "<td align='left' width=250 >There are <b>$totalrows</b> matches to your query</td>";   //message saying how many matches for query            
                        echo "<table align='center' border=1  background=/graycolour.gif><tr>";
                        echo "<td align='left' width=125 bgcolor='#11d163' color='#FF0000'><b>Supplier</b></td>";
                        echo "<td align='left' width=125 bgcolor='#11d163'><b>Color</b></td>";
                        echo "<td align='left' width=125 bgcolor='#11d163'><b>Details</b></td>";
                        echo "<td align='center' bgcolor='#11d163'><b>Picture</b></td>";
                        echo "</tr>";
                        
                        while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        
                        echo "<tr><td align='left'>".$row["Manufacturer"]."</td>";
                        echo "<td align='left'>".$row["Colour"]."</td>";
                        echo "<td align='left'>".$row["Brick Name"]."</td>";
                        echo "<td align='left'>".$row["Image"]."</td>";
                         echo "</tr>";
                  }
              }
                 echo "</table>";

        if($page != 1){ 
        $pageprev = $page--;
        
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); 
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = ceil($totalrows / $limit);
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
        }
    }


    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
         
        echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
    }else{
        echo("NEXT".$limit); 
    }
    
    mysql_free_result($result);        
                
?>  

Link to comment
https://forums.phpfreaks.com/topic/48736-pagination-help-d/
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.