[eluser]ahandy[/eluser]
I'm working with the cart library, and I want a page that shows the items from the MySQL table, shows the add to cart link if the if isn't already in the cart, and shows Added to cart if it already is.
I know the concept, however whenever I try doing it, it either works with just 1 item (meaning, if I add only an item to the cart, it works fine, however if I add more than an item, the code starts getting messed up.)
Code:
// Checking to see if there is anything in the cart
if($this -> cart -> contents())
{
// Foreach to get arrays from the cart lib
foreach($this -> cart -> contents() as $wut)
{
// Checking to see if item is already added
if(in_array($item["Name"], $wut))
{
echo "<td>Added to cart.</td></tr>";
}
else
{
echo "<td>Add</td>";
echo "</tr>";
}
}
}
Like I said, if it's only an item, it works.
However if it's two, it shows Added to cart or Add like 5 times for each item (depending on how many items are available).
What I think the problem is, is that everything is working fine, however I need a way to only do the foreach if the item matches the foreach or w/e. I dunno, I'm kind of lost.
Help?
(I feel that my question isn't clear enough, if it isn't please tell me).
UPDATE:
Screenies: