Hi there,
I'm learning PHP and working on building an ecommerce site using a MVC.
I can display all six categories from the database on the index page however I only want to show four of these, as the links at the top will be the six categories.
By using the next() method I can display all six categories:
<?php
while ($categories->next()) {
?>
<section class="product">
<a href="products/<?= $categories->getURL() ?>"><h3 class="upper"><?= $categories->getName() ?></h3></a>
<br/>
<img src="<?= IMAGE_URL . $categories->getImage() ?>" style="width:80%; height:auto;" alt="Menu Tab"/>
<h3 class="under"><a href="products/<?= $categories->getURL() ?>">SHOP NOW >></a></h3>
</section>
<?php
}
}
}
?>
I am wondering how to only extract certain products (each has a catID in the database). I thought the switch statement might be the answer and here was my attempt that did not work. I guess I am still not saying which catID to get but unsure how to fix this. Or is there another way not using switch?
while ($categories->next()) {
switch ($categories->getID()) {
case 1:
case 2:
case 3:
case 4:
?>
<section class="product">
<a href="products/<?= $categories->getURL()?>"><h3 class="upper"><?=$categories->getName() ?></h3></a>
<br/>
<img src="<?=IMAGE_URL. $categories->getImage()?>" style="width:80%; height:auto;" alt="Menu Tab"/>
<h3 class="under"><a href="products/<?= $categories->getURL()?>">SHOP NOW >></a></h3>
</section>
<?php
break;
default:
return "";
}
}
}
}
?>
Any help would be greatly appreciated!
Cheers