Hey all,
I'm not sure why this script doesn't work - it's from How to do everything with PHP & MySQL. Any ideas? it just comes up with one catalog entry:
<?php
// look for catalog file
$catalogFile = "catalog.dat";
// file is available, extract data from it
// place into $CATALOG array, with SKU as key
if (file_exists($catalogFile))
{
$data = file($catalogFile);
foreach ($data as $line)
{
$lineArray = explode(':', $line);
$sku = trim($lineArray[0]);
$CATALOG[$sku]['desc'] = trim($lineArray[1]);
$CATALOG[$sku]['price'] = trim($lineArray[2]);
}
}
else
{
die("Could not find catalog file");
}
?>
<table border="0" cellspacing="10">
<?php
// print items from the catalog for selection
foreach ($CATALOG as $k => $v)
{
echo "<tr><td colspan=2>";
echo "<b>" . $v['desc'] . "</b>";
echo "</td></tr>\n";
echo "<tr><td>";
echo "Price per unit: " . $CATALOG[$k]['price'];
echo "</td><td>Quantity: ";
echo "<input size=4 type=text name=\"a_qty[" . $k . "]\">";
echo "</td></tr>\n";
}
?>
<tr>
<td colspan="2">
<input type="submit" name="add" value="Add items to cart">
</td>
</tr>
</table>
and the catalog.dat file:
101:AA batteries (pack of 2):2.99
102:AA batteries (pack of 4):5.49
103:Backpack (black): 69.99
104:Money belt with 6 compartments (black):13.49
105:Haversack (red):199.99
106:Swiss Army knife (6 blades including can opener and scissors):24.99
107:Duffel bag (steel gray):28.50
Cheers
Edd