Currently I have the following section of code:
<?php if($sales_pages): ?>
<?php foreach($sales_pages as $sale): ?>
<div id ="sales">
<span class"thumbnail"><a href="<?=base_url()?>page/sales/viewsale/<?=$sale->id?>"><img class="thumbnailImg" src="<?=base_url()?>includes/uploads/sales/thumbs/<?=$sale->thumbname?>" alt=""/></a>
<span class="location"><?= $sale->location?></span>
<span class="price"><?= $sale->price?></span>
</span>
</div>
<?php endforeach; ?>
What I am trying to do is the following:
When there are 0 sales (fetched from database) in the foreach I would like my code to display a message
Is elseif the correct way to do this?
No. You should use
else. It’s basically the same as sayingelseif(True). You’ll end up with something like:You can (and should) read more about the control structures in PHP in the PHP documentation.
Oh, and by the way. It looks like you are using CodeIgniter. Did you know that you can use the
site_urlfunction instead of prepending stuff withbase_url()? You’d then write the url of your link like this (although I think you have a syntax error in that part of your code above):