I am developing my first e-commerce site and have run into a slight problem with the page counter. As you can tell in my code below, I set my number/Pg and start page level vars as follows:

$numPerPage=3;
$start=0;

I know I am missing a limit in my SQL stmt, but do exactly know where. When I execute the SQL stmt with the limit, I am returned a page that displays ALL my products with the correct amout of pg numbers (e.g. what I would like is to have three products display/page starting with the first product...as indicated in my vars above. I am getting 32 products returned instead).

Any clues as to what I have done and what I need to do?

Thanks

venetian_jigsaw

<?php
session_start();
error_reporting(E_ALL);
$cellContent="&nbsp;";
$sesid=session_id();

include("../include/dbconn.inc");    

$numPerPage=3;
$start=0;

if (isset($_GET["start"]))
{
  $start=$_GET["start"];  
}

function writePageNumbers($numOfProducts,$numPerPage,$start,$category)
{
        $numOfPages=$numOfProducts/$numPerPage;
        //echo "numOfProducts=".$numOfProducts;
        //echo "numPerPage=".$numPerPage;
        //echo "numOfPages=".$numOfPages;
        $numOfPages=ceil($numOfPages);
        //echo $numOfPages;
        //die;
        echo "<table bgcolor='#FFFACD'>";
        echo "<tr style='background-color:#FFFACD'>";

    $currentPage=($start/$numPerPage)+1;

    for($i=1;$i<=$numOfPages;$i++)
        {

           if($i==$currentPage)
            {
             echo "\n<td>";
             if ($category!="")
             {
               echo"<span style='font-weight:bold;font-size:12pt;font-family:arial;color:#999999'></span>";
             }
             echo "<span style='color:#999999'>";
             echo "[";
             echo $i;
             echo "]";
             echo "</span>";
             echo "</td>\n";
            }
            else
            {
            $start=($i-1) * $numPerPage;
             echo "\n<td>";
             echo "[";
             echo "<a href='products.php?start=$start";
             if (isset($_GET["category"]))
             {
               echo "&category=$category";
             }
             if (isset($_GET["type"]))
             {
               $searchText=$_GET["searchText"];
               $searchWhat=$_GET["searchWhat"];
               echo "&type=search";
               echo "&searchText=$searchText";
               echo "&searchWhat=$searchWhat";
             }       
             echo "'>";
             echo $i;
             echo "</a>";
             echo "]";
             echo "</td>\n";
            }
         }
           echo "</tr>";
           echo "</table>";
}
//echo $category;
//die;

// create sql statement for entire catalog
  $oursql="select * from tblproducts";

//echo $oursql;
//die;

//create sql stmt for category only

//If category is set and mfgname is not
$category="";
if (isset($_GET["category"]) && !isset($_GET["mfgname"]))
{
    if ($_GET["category"]=="Entire Site")
    {
          $oursql="select * from tblproducts";

    }
    else
    {
          $category=$_GET["category"];
          $oursql="select * from tblproducts where category='$category'";
    }
}
//echo $category;
//die; 

//If category is not set and mfgname is
if (!isset($_GET["category"]) && isset($_GET["mfgname"]))
{
      $mfgname=$_GET["mfgname"];
      $oursql="select * from tblproducts where mfgname='$mfgname'";
}
//echo $mfgname;
//die; 

//If category and mfgname is set
if (isset($_GET["category"]) && isset($_GET["mfgname"]))
{
    if ($_GET["category"]=="Entire Site")
    {
       $mfgname=$_GET["mfgname"];
       $oursql="select * from tblproducts where mfgname='$mfgname'";
    }
    else
    {

      $category=$_GET["category"];
      $mfgname=$_GET["mfgname"];
      $oursql="select * from tblproducts where category='$category' and mfgname='$mfgname'";
    }
}
//echo $category;
//echo $mfgname;
//die; 

//echo $oursql;
//die;

//Execute the sql stmt
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo die;

$numOfProducts=mysql_num_rows($myresult);
//echo $numOfProducts;
//die;
?>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us"></meta>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title>Wee-Be-Babies - Catalog</title>

<script type="text/javascript">var ace_path = '../menu/';</script>
<script type="text/javascript" src="../menu/acemenu_loader.js"></script>
<script type="text/javascript">

    function openWindow(modelnum)
    { 
     prodWindow=window.open("lgImg.php?modelnum="+modelnum+"","null","width=420,height=420,status=0,location=0,left=300,top=225,directories=0,fullscreen=0,toolbar=0,menubar=0,scrollbars=0,resizable=0");
     prodWindow.focus();
    }
</script>

<link href="menu.css"
          rel="stylesheet"
          type="text/css" />
</head>

<body background='../images/bgwhitepacirattle.gif'  width='200' height='200'>
<form
    action='products.php'
    method='get'>

<div class='center1'>
<br /><br />
    <table border='1px'
          border-size='2px'
          bordercolor="#000000"
          width='95%'
          cellspacing='0'
          cellpadding='0'>
         <tr>
            <td>
            <div class='center1'>
            <table border='0'
                  width='100%'
                  cellspacing='0'
                  cellpadding='0'>
                <tr>
                  <td>
                    <!-- Logos -->
                    <table border='0'
                          width='100%'
                          cellspacing='0'
                          cellpadding='0'>
                        <tr>

                             <td style='text-align:left; background-color:#FFFACD'><img src="../images/blank.gif" alt="" style="width: 187px; height: 150px; background-color:#FFFACD; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/babyMotherImg.png', sizingMethod='scale')"</td>

                            <td width='50%' style='background-color:#FFFACD'><!-- 
                            <img src="./images/blank.gif" alt="" style="width: 354px; height: 129px; background-color:#FFFACD; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='./images/babyTimeLogo.png', sizingMethod='scale')" -->
                             </td>
                              <td valign='bottom' style='background-color:#FFFACD'><?php include( '../include/acctAccess.inc');  ?></td>

                          </tr>
                         </table>
                      </td>
                      </tr>
                  </table>
                   </div>

                <div class='center1'>
                <table border='0'
                      width='100%'
                      cellspacing='0'
                      cellpadding='0'>
                    <tr>

                        <!-- Home menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/home.js"></script><script language="JavaScript1.2" type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- About menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/about.js"></script><script language="JavaScript1.2" type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- Catalog menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/catalog.js"></script><script language="JavaScript1.2" type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- Carseats menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/carseats.js"></script><script language="JavaScript1.2" type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- Furniture menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/furniture.js"></script><script language="JavaScript1.2" type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- Strollers menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script language="JavaScript1.2" type="text/javascript" src="../menu/strollers.js"></script><script type="text/javascript">ACEDisplayMenu();</script></td>

                        <!-- Contact menu -->
                        <td style='text-align:center; background-color:#7BA7F9'><script type="text/javascript" src="../menu/contact.js"></script><script type="text/javascript">ACEDisplayMenu();</script></td>
                    </tr>
                    <tr>
                        <td colspan='7' width='100%' style='background-color:#FFFACD'><img src='../images/blank.gif' alt="" height='10' /></td>
                    </tr>
                </table>
                <table border='0'
                      width='100%'
                      cellspacing='0'
                      cellpadding='0'>
                    <tr valign='top'>
                        <td style='background-color:#7BA7F9' width='20%'>
                            <table border='0'
                              width='100%'
                              cellspacing='0'
                              cellpadding='0'>
                          <tr valign='top'>
                                <td style='background-color:#7BA7F9' width='20%'><?php include( '../include/login.php'); ?></td>
                              </tr>
                             </table>
                      </td>
                      <td style='text-align:center;background-color:#FFFACD'>
                        <table border='0'
                              cellspacing='0'
                              cellpadding='0'
                              width='100%'
                              bgcolor='#FFFACD'>

<tr>
                        <td width='25%'><?php writePageNumbers($numOfProducts,$numPerPage,$start,$category); ?></td>

                        <td width='75%' style='text-align:right'><?php include("../include/search.php"); ?></td>
                         </tr>

Edited 3 Years Ago by pyTony: fixed formatting

I did not read over the entire thing there but you probably want to do something like this:


$oursql="select * from tblproducts" LIMIT $start,$end;


Then on your creation of numpages set start and end +10 results or something.

so that page one's sql when rendered says

$oursql="select * from tblproducts LIMIT 0,10";

then page 2 says

$oursql="select * from tblproducts LIMIT 10,20";

and so on...

Follow?

This article has been dead for over six months. Start a new discussion instead.