venetianjigsaw
Programmer
Hi,
On my same e-commerce site, I have a catalog that contains 22 products.
Essentially, I also have three categories which comprise the catalog:
Carseats (cst) 6 products
Furniture (frn) 10 products
Strollers (str) 6 products
My problem is that when I display each category, the numOfProducts returned is also 22. Can/will someone please take a look at my code and tell me what I have done wrong?
Thanks
VJ
<?php
session_start();
error_reporting(E_ALL);
$cellContent=" ";
$sesid=session_id();
echo "-";
//foreach($_GET as $key => $value)
//{
//print "Value of " . $key . " = " . $value . "<br />";
//}
//die;
//echo "-";
$numPerPage=3;
$start=0;
if (isset($_GET["start"]))
{
$start=$_GET["start"];
}
function writePageNumbers($numOfProducts,$numPerPage,$start,$category)
{
$numOfPages=$numOfProducts/$numPerPage;
//echo "numOfProd=".$numOfProducts;
//echo "numPerPg=".$numPerPage;
//echo "numberOfPages=".$numOfPages;
$numOfPages=ceil($numOfPages);
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'>$category</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>";
}
include("../include/dbconn.inc");
$oursql="select * from tblproducts";
//echo $oursql;
//die;
//Execute SQL stmt
$myresult = mysql_query($oursql) or die (mysql_error());
$numOfProducts=mysql_num_rows($myresult);
//echo $numOfProducts;
// create sql stmt for entire catalog
$oursql="select * from tblproducts limit $start, $numPerPage";
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (isset($_GET["category"]) && !isset($_GET["mfgname"]))
{
if ($_GET["category"]=="Entire Site")
{
$oursql="select * from tblproducts limit $start, $numPerPage";
}
else
{
$category=$_GET["category"];
$oursql="select * from tblproducts where category='$category' limit $start, $numPerPage";
}
}
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (!isset($_GET["category"]) && isset($_GET["mfgname"]))
{
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where mfgname='$mfgname' limit $start, $numPerPage";
}
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (isset($_GET["category"]) && isset($_GET["mfgname"]))
{
if ($_GET["category"]=="Entire Site")
{
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where mfgname='$mfgname' limit $start, $numPerPage";
}
else
{
$category=$_GET["category"];
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where category='$category' and mfgname='$mfgname' limit $start, $numPerPage";
}
}
//echo $oursql;
//die;
//Execute the sql stmt
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo die;
?>
<table>
<tr>
<td width='25%'><?php writePageNumbers($numOfProducts,$numPerPage,$start,$category); ?></td>
</tr>
</table>
On my same e-commerce site, I have a catalog that contains 22 products.
Essentially, I also have three categories which comprise the catalog:
Carseats (cst) 6 products
Furniture (frn) 10 products
Strollers (str) 6 products
My problem is that when I display each category, the numOfProducts returned is also 22. Can/will someone please take a look at my code and tell me what I have done wrong?
Thanks
VJ
<?php
session_start();
error_reporting(E_ALL);
$cellContent=" ";
$sesid=session_id();
echo "-";
//foreach($_GET as $key => $value)
//{
//print "Value of " . $key . " = " . $value . "<br />";
//}
//die;
//echo "-";
$numPerPage=3;
$start=0;
if (isset($_GET["start"]))
{
$start=$_GET["start"];
}
function writePageNumbers($numOfProducts,$numPerPage,$start,$category)
{
$numOfPages=$numOfProducts/$numPerPage;
//echo "numOfProd=".$numOfProducts;
//echo "numPerPg=".$numPerPage;
//echo "numberOfPages=".$numOfPages;
$numOfPages=ceil($numOfPages);
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'>$category</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>";
}
include("../include/dbconn.inc");
$oursql="select * from tblproducts";
//echo $oursql;
//die;
//Execute SQL stmt
$myresult = mysql_query($oursql) or die (mysql_error());
$numOfProducts=mysql_num_rows($myresult);
//echo $numOfProducts;
// create sql stmt for entire catalog
$oursql="select * from tblproducts limit $start, $numPerPage";
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (isset($_GET["category"]) && !isset($_GET["mfgname"]))
{
if ($_GET["category"]=="Entire Site")
{
$oursql="select * from tblproducts limit $start, $numPerPage";
}
else
{
$category=$_GET["category"];
$oursql="select * from tblproducts where category='$category' limit $start, $numPerPage";
}
}
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (!isset($_GET["category"]) && isset($_GET["mfgname"]))
{
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where mfgname='$mfgname' limit $start, $numPerPage";
}
//echo $oursql;
//die;
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo 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 $oursql;
//die;
if (isset($_GET["category"]) && isset($_GET["mfgname"]))
{
if ($_GET["category"]=="Entire Site")
{
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where mfgname='$mfgname' limit $start, $numPerPage";
}
else
{
$category=$_GET["category"];
$mfgname=$_GET["mfgname"];
$oursql="select * from tblproducts where category='$category' and mfgname='$mfgname' limit $start, $numPerPage";
}
}
//echo $oursql;
//die;
//Execute the sql stmt
$myresult = mysql_query($oursql) or die (mysql_error());
//echo $myresult;
//echo die;
?>
<table>
<tr>
<td width='25%'><?php writePageNumbers($numOfProducts,$numPerPage,$start,$category); ?></td>
</tr>
</table>