Jump to content

Product list page


ycoleman

Recommended Posts

???I am trying to create a Product list page that can list the pictures of each product and their description whenever I click on a Subcategory link from the database.  I am not sure how to do this but here is the code I have so far:

 

<?php error_reporting(E_ALL);

ini_set('display_errors', '1');?>

 

<?php

if (isset($_GET['CatID']))

{

    $thisCatID = (int)$_GET['CatID'];

}

else

 

{

    $thisCatID = 1;

}

?>

 

<?php //product list

$sql_2 ="SELECT * FROM tblProduct";

$result = @mysql_query($sql_2,$db) or die(mysql_error());

 

?>

 

tblProduct is the table

Columns are ProductName, Description, UnitPrice, Inventory,CatID, SubCatID, SmallImg, and LargeImg

Link to comment
https://forums.phpfreaks.com/topic/44715-product-list-page/
Share on other sites

You need to put the data that you extracted from the database in an array. Example:

 

while($row= mysql_fetch_array($result)){
$productname = $row['ProductName'];
$description = $row['Description'];
$unitprice = $row['UnitPrice'];
$inventory = $row['Inventory'];
$catid = $row['CatID'];
$subcatid = $row['SubCatID'];
$smallimg = $row['SmallIMG'];
$largeimg = $row['LargeIMG'];

echo "$productname";
echo "$description";
echo "$unitprice";
echo "$inventory";
echo "$catid";
echo "$subcatid";
echo "$smallimg";
echo "$largeimg";
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/44715-product-list-page/#findComment-217126
Share on other sites

:)Thanks for that last response, I'm on track so far but I get an error message that says "Notice: Undefined variable: SubCatID "  and I can't get my list to display right.  I wanted my SmallIMG to be on the right and my and my ProductName to appear right beside it along with the UnitPrice.  ???

 

 

Here is my code:

 

<?php error_reporting(E_ALL);
ini_set('display_errors', '1');?>

<?php
if (isset($_GET['SubCatID']))
{
    $thisCatID = (int)$_GET['SubCatID'];
}
else

{
    $thisCatID = 1;
}
?>

<?php //product list
$sql_2 ="SELECT * FROM tblProduct";
$result = @mysql_query($sql_2,$db) or die(mysql_error());

while($row= mysql_fetch_array($result)){
$smallimg = $row['SmallImage'];
$productname = $row['ProductName'];
$unitprice = $row['UnitPrice'];
//$description = $row['Description'];

//$inventory = $row['Inventory'];
$catid = $row['CatID'];
$subcatid = $row['SubCatID'];

//$largeimg = $row['LargeImage'];

echo "<p>" . "$productname" . "</p>"; echo "$" ."$unitprice";
echo "<a href=`ProductList.php?SubCatID=1" . $SubCatID . "`>" . $productname . "</a><br>";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/44715-product-list-page/#findComment-218464
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.