Forum Moderators: coopster
<?php
$countbanner = "SELECT count(*) FROM banners";
$counterquery = mysql_query($countbanner);
$displaycounter = mysql_fetch_array($counterquery);
$number_of_banners = $displaycounter[0];
if (empty($_SESSION['current_banner'])) {
$_SESSION['current_banner'] = '1'; }
$SQL = "SELECT image, link FROM banners WHERE id = '". $_SESSION['current_banner'] ."'";
$displayquery = mysql_query($SQL);
$displayresult = mysql_fetch_array($displayquery);
if (!empty($displayresult[0]))
{
echo '<a href="';
echo $displayresult[1];
echo '">';
echo '<img src = "images/banner_images/';
echo $displayresult[0];
echo '" border="0">';
echo '</a>';
}
$_SESSION['current_banner']++ ;
if (($_SESSION['current_banner']) > ($number_of_banners)) {
$_SESSION['current_banner'] = '1'; }
?>
Habtom
As Michal said, if you're not starting your session, that would be one case.
If your first query is getting a count of zero for $displaycounter, then you would also be getting set to 1 every time, so you might want to test
if (!empty($number_of_banners) && $_SESSION['current_banner'] > $number_of_banners) {
$_SESSION['current_banner'] = '1'; }
You cannot *start* a session after output is sent, because starting a session involves at least an attempt to set or access a cookie, which involves sending HTTP headers, which must precede all output. You can, however, increment a session variable or otherwise manipulate it, as this does not involve any HTTP headers..