Jump to content

Pagination


hbalagh

Recommended Posts

I think I almost have this i have it so it only shows 12 images on the first page of each category but can't figure out how the link should be and get it to work..  i've done this before on another site but it didn't have categories to deal with, the code is a little messy right now.. but hoping someone can help me on this

 

Thanks

 

<?php

include ("includes/db.conf.php");
include ("includes/connect.inc.php");include ("header.php");
if (isset($_GET['cat'])){
$query = "SELECT * from products where category='$_GET[cat]' ";
$mysqlresult = mysql_query($query);

$queryc=mysql_query("select * from categories where id='$_GET[cat]' ");
$rowqueryc=mysql_fetch_array($queryc);
echo "<div id='featureindex'>";
echo "<h3>$rowqueryc[name]</h3>";
}
   $qry = mysql_query ("
       SELECT * FROM `products` where category='$_GET[cat]'");
      if ($row=mysql_fetch_array($qry))
      {
        do 
        {
          $sName= $row["name"];
          $sphoto= $row["photo"];
          $sdescription= $row["description"];
        } while ($row = mysql_fetch_array($qry));
      }
    $limit          = 12;                
    $query_count    = "SELECT count(*) FROM `products` where category='$_GET[cat]'";     
   $result_count   = mysql_query($sName);     
$totalrows      = mysql_num_rows($qry); 
    	if(empty($page)){ 
        $page = 1; 
    } 
     $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT * FROM `products` where category='$_GET[cat]' LIMIT $limitvalue, $limit";         
    $result = mysql_query($query) or die("Error: " . mysql_error()); 
    if(mysql_num_rows($result) == 0){ 
        echo("Nothing to Display!"); 
    } 
   while($row = mysql_fetch_array($result)){ 
   
echo "<div id='feature'><a href='product.php?product=$row[id]'><div id='productborder'><img src='images/thumbs/$row[photo]' border=0></div></a>";
echo($row["name"]); 
echo "</div>\n";
    } 
echo "<br />\n";
  
    $numofpages = $totalrows / $limit; 
    for($i = 1; $i <= $numofpages; $i++){ 
        if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"productlist.php?cat=$rowqueryc[id]page=$i\">$i</a> "); 
        } 
    } 
    if(($totalrows % $limit) != 0){ 
        if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"productlist.php?cat=$rowqueryc[id]page=$i\">$i</a> "); 
        } 
   	echo "</div>\n";
    } 
    mysql_free_result($result); 
include_once 'footer.php';
?>

Link to comment
Share on other sites

well i found a mistake on your script

 

on all the sql commands you have something like this:

 

"SELECT * FROM categories WHERE id='$_GET[cat]'"

 

you are forgetting the single quotes around the word cat

 

try making it a variable and do something like

 

$cat = $_GET['cat'];

$change_queries_to = mysql_query("SELECT * FROM categories WHERE id='$cat'");

Link to comment
Share on other sites

thanks, but i still get confused by terminology the technical terms and after changing the below still can't get the links to work for it...

 

 

or

 

<?php
$queryc=mysql_query("select * from `categories` where `id`='".$_GET['cat']."' ");
$rowqueryc=mysql_fetch_array($queryc);
?>

 

 

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.