I am creating a simple order cart.
In essence, a user clicks order, the products id is added to a session variable ($order) as an array. When viewing the “cart” a check occurs where if a value in the session variable is equal to the id of a specific row in a mysql table, that specific row is returned as an item that was ordered. For each value in the session variable, this process should reoccur.
Here is the bit of code that I am battling with:
foreach ($order as $item)
{
while($row = mysql_fetch_assoc($productsSql))
{
$itId = $row['id'];
$itDesc = $row['desc'];
$itPrice1 = $row['price1'];
if ($item == $itId)
{
$pageContent .= '
<tr>
<td>'.$itDesc.'</td>
<td>
R'.number_format($itPrice1, 2).'
</td>
</tr>
';
}
}
}
The “$orders” variable is this:
session_start();
if (!isset($_SESSION['order']))
{
$_SESSION['order'] = array();
}
Can anyone spot any problems with this?
$productsQuery = 'SELECT `id`, `refCode`, `desc`, `pack`, `measure`, `quantity`, `deptCode`, `taxable`, `price1`, `price2`, `crdCode`, `cost1`, `cost2` FROM `products` ORDER BY `desc` ';
$productsSql = mysql_query($productsQuery) or die(mysql_error());`
try this
mysql_data_seek( $productsSql, 0);
hope that helps