i working on project (real estate) , need display list of properties. (pictures) properties in database. properties can have 2 'objects_status': 1=for sale, 2=sold. sold properties display 'sold' banner on top of image.
i did manage display properties, using 'foreach'. displays properties randomly. want add following: there has 2 sold properties on list.
i don't want use 2 seperate foreach (first 1 show 2 sold en second 1 show sale properties), show 2 sold properties randomly between sale properties.
the code use:
<?php foreach($abuildings $abuilding): ?> <div class="span2 <?php echo ($abuilding['objects_status'] == 1 ? 'sold' : ''); ?>"> <figure> <?php if($abuilding['objects_status'] == 1){ echo '<div class="sold-banner">afgelopen</div>';} else if($abuilding['objects_status'] == 2){ echo '<div class="verkocht-banner">verkocht</div>';} else{ echo '<div class="days-left">' . $abuilding['daysleft'] . '</div>';} ?> <img src="/uploads/woningen/thumb/<?=$abuilding['objects_photo_thumb']?>" alt=""> </figure> <ul> <li>normaal € <?php echo number_format($abuilding['objects_price'], 0, '', '.'); ?></li> <li class="now">nu € <?php echo number_format($abuilding['objects_discount_price'], 0, '', '.'); ?></li> <li>korting <?php echo round(-1 * ($abuilding['objects_discount_price'] / $abuilding['objects_price'] * 100 - 100)); ?>%</li> </ul> </div> <?php endforeach; ?> i can't seem work. suggestions?
i suggest changing db query pull results want. example if writing in sql:
select * properties sale sale.objects_status = "for sale" union select * properties sold sold.objects_status = "sold" limit 2 i'm guessing db schema obviously. can foreach on results original code.
Comments
Post a Comment