954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php counter

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=" ";
$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 "";
echo "";

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

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

if($i==$currentPage)
{
echo "\n";
if ($category!="")
{
echo"";
}
echo "";
echo "[";
echo $i;
echo "]";
echo "";
echo "\n";
}
else
{
$start=($i-1) * $numPerPage;
echo "\n";
echo "[";
echo "";
echo $i;
echo "
";
echo "]";
echo "\n";
}
}
echo "";
echo "";
}
//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;
?>

Wee-Be-Babies - Catalog



<?php include( '../include/acctAccess.inc'); ?>




<?php include( '../include/login.php'); ?> <?php writePageNumbers($numOfProducts,$numPerPage,$start,$category); ?> <?php include("../include/search.php"); ?>

venetian_jigsaw
Newbie Poster
15 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

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?

techniner
Posting Pro
527 posts since May 2005
Reputation Points: 12
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You