Hi everyone,
The following code in a controller file shows that I have an array that's been built after querying the database (I haven't shown the select query so the post won't be too long):
$items = array();
while ($row = mysqli_fetch_array($result))
{
$items[] = array('itemTitle' => $row['itemTitle'], 'itemSKULadies' => $row['itemSKULadies'], 'itemSKUMen' => $row['itemSKUMen'], 'itemDescLadies' => $row['itemDescLadies'], 'itemDescMen' => $row['itemDescMen'], 'itemPriceBoth' => $row['itemPriceBoth'], 'itemPriceFemale' => $row['itemPriceFemale'], 'itemPriceMale' => $row['itemPriceMale'], 'itemColoursBoth' => $row['itemColoursBoth'], 'itemColoursFemale' => $row['itemColoursFemale'], 'itemColoursMale' => $row['itemColoursMale'], 'Lsize' => $row['Lsize'], 'Msize' => $row['Msize'], 'itemType' => $row['itemType'], 'itemSwatchBoth' => $row['itemSwatchBoth'], 'itemSwatchFemale' => $row['itemSwatchFemale'], 'itemSwatchMale' => $row['itemSwatchMale'], 'itemImage' => $row['itemImage'], 'subcategory' => $row['subcategory']);
}
include 'catalogue_consumer.php';
exit();
}
?>
You can see above that it includes a template file catalogue_consumer.php.
Part of this template file contains the code shown below.
<?php
if ($items['subcategory'] == Formalwear) {
echo "<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=1\">Suits</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=10\">Vests</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=16\">Formal Shirts</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=12\">Bow Ties</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=15\">Cummerbunds</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=11\">Formal Ties</a>
<a href=\"$url_consumer/index.php?subcatID=6&itemTypeID=14\"> Cravats </a>";
}
?>
You can see that I'm referencing the 'subcategory' from the $items array above:
if ($items['subcategory'] == Formalwear)
When I test I get an Undefined index error:
Notice: Undefined index: subcategory in /Applications/MAMP/htdocs/site/consumer/catalogue/catalogue_consumer.php on line 151
This errors refers to the line above, ie
if ($items['subcategory'] == Formalwear)
I don't understand why it's saying it's undefined since it's in the array mentioned above. So I just wondered how I can define it so the error will be eliminated?
Appreciate any assistance.