PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php $r = mysql_query("SELECT * FROM announcement_banners") or die(mysql_error());
if(@mysql_num_rows($r) == 0) {
echo'<img src=../images/'.$pop['defaultbanner'].'>';
} else {
while($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
echo'<a href='.$row['link_url'].'><img src='.$row['banner_url'].'></a></br>
</br>';
}
}
?>
now as you see I have it telling it that if its 0 to show the default banner and I know this will need to change but not sure how to code it/word it to make it do what I need as stated above.
any help would be great
Your code currently outputs 1 default banner or X custom banners. Since you want X custom banners and 5-X default banners you need to rearrange the logic. First step is removing the if block since it's not a matter of "if there are banners then show them" but "show whatever is available".
<?php
// to avoid deleting banners, make sure you return the results in some kind of order. probably newest first
// also limit the query so it only returns up to the limit - don't want 6 banners when you're only showing 5
$r = mysql_query("SELECT * FROM announcement_banners ORDER BY something so more recent banners come first LIMIT $number_of_banners_to_show") or die(mysql_error());
while($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
echo'<a href='.$row['link_url'].'><img src='.$row['banner_url'].'></a></br>
</br>';
}
After the custom banner loop have another loop to count out the 5-X default banners.