Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shopping cart: Displaying products on different pages

Status
Not open for further replies.

mancroft

Programmer
Oct 26, 2002
267
GB
I am doing a shopping cart and have put the products into a mysql database.

The code below displays all the products on one page.

What I want to do is display product type A (3 items) on one page, product type B (4 items) on another page, product type C (2 items) on another page and so on.

What is the best way to go about this?

Thanks for your help.

CODE BELOW>>>>>>>>


include("db.php");

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");

?>
<html>
<head>
<title> Product List </title>
</head>
<body bgcolor=&quot;#ffffff&quot;>
<h1>Products</h1>
<table width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;>
<tr>
<td width=&quot;30%&quot; height=&quot;25&quot; bgcolor=&quot;red&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;white&quot;>
&nbsp;&nbsp;<b>Product</b>
</font>
</td>
<td width=&quot;10%&quot; height=&quot;25&quot; bgcolor=&quot;red&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;white&quot;>
<b>Price</b>
</font>
</td>
<td width=&quot;50%&quot; height=&quot;25&quot; bgcolor=&quot;red&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;white&quot;>
<b>Description</b>
</font>
</td>
<td width=&quot;10%&quot; height=&quot;25&quot; bgcolor=&quot;red&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;white&quot;>
<b>Add</b>
</font>
</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width=&quot;30%&quot; height=&quot;25&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;black&quot;>
<?php echo $row[&quot;itemName&quot;]; ?>
</font>
</td>
<td width=&quot;10%&quot; height=&quot;25&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;black&quot;>
$<?php echo $row[&quot;itemPrice&quot;]; ?>
</font>
</td>
<td width=&quot;50%&quot; height=&quot;25&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;black&quot;>
<?php echo $row[&quot;itemDesc&quot;]; ?>
</font>
</td>
<td width=&quot;10%&quot; height=&quot;25&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;black&quot;>
<a href=&quot;cart.php?action=add_item&id=<?php echo $row[&quot;itemId&quot;]; ?>&qty=1&quot;>Add Item</a>
</font>
</td>
</tr>
<tr>
<td width=&quot;100%&quot; colspan=&quot;4&quot;>
<hr size=&quot;1&quot; color=&quot;red&quot; NOSHADE>
</td>
</tr>
<?php
}
?>
<tr>
<td width=&quot;100%&quot; colspan=&quot;4&quot;>
<font face=&quot;verdana&quot; size=&quot;1&quot; color=&quot;black&quot;>
<a href=&quot;cart.php&quot;>Your Shopping Cart &gt;&gt;</a>
</font>
</td>
</tr>
</table>
</body>
</html>
 
One way is to pass the variable to the script that decides which product type to display and controlling the query depending on that
eg.
$query = &quot;select * from items where product_type='$product_type' order by itemName asc&quot; ;

where $product_type is type 'A','B',or 'C'


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top