Jump to content

horizontal scrolling banners


nomanoma

Recommended Posts

hi:

i'm trying to make a scrolling banner ads script. the thing is i want the banners to be shown in one row beside each other. what i've done makes the banners show under each other.

i can't use just html and make a tabel with cells and add the banner links because i have to get the urls from a database like this:

$res_banners = @mysql_query("SELECT * FROM scbuttons where status=1 and max>shown ORDER BY RAND() LIMIT 10");

 

i appreciate any help.

here's the complete code i'm using:

 

<?php

 

$res_banners = @mysql_query("SELECT * FROM scbuttons where status=1 and max>shown ORDER BY RAND() LIMIT 1");

while($banners = @mysql_fetch_array($res_banners)) {

 

mysql_query("update scbuttons set shown=shown+1, show_views=show_views+1 where id=".$banners['id']);

 

    if ($banners[bannerurl] != "" ) {

 

?>

 

<?

if( session_is_registered("ulogin") )

 

{ ?>

 

 

 

<center><table style="width:800; height: 170px;"

cellspacing="0" cellpadding="0" bordercolor=#000000 border="1" bgcolor=#FFFFFF><tr><td>

 

 

 

 

 

 

<marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();"><a href="<? echo "$domain/scbuttonclick1.php?id=".$banners['id']; ?>" target="_blank"><img src="<? echo $banners['bannerurl']; ?>" style="float:left;" border="0"></a></marquee>

 

 

 

<?

 

}

 

else

{ ?>

 

 

 

       

      <marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();"><a href="<? echo "$domain/scbuttonclick.php?id=".$banners['id']; ?>" target="_blank"><img src="<? echo $banners['bannerurl']; ?>" style="float:left;" border="0"></a></marquee>

 

    <?

 

}

 

}

 

    }

 

 

 

?>

</tr></td></table></center>

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/
Share on other sites

I don't have your database structure here, but I loaded the page without the actual graphics and it seems OK to me. Can you point me to the website it isn't behaving on, or post a screenshot?

 

the only problem i have is that it displays the buttons over each other and not on the same row.

i'm attaching a snapshot.

 

[attachment deleted by admin]

OK, got it. With the <table><tr> and <td> tags all inside the while loop, it was creating a new table for every record returned from the database. I moved those outside the while() loop, so it should be fine now. Also cleaned up the code a little bit, and indented it for you. Let me know if there are any issues.

 

Also, it likely isn't a big deal right now, but selecting a random row with "ORDER BY RAND()" will get very slow on a large database table. Google 'why order by rand() is bad' and just keep it in mind for the future . . .

 

<?php
echo '<center><table style="width:800; height: 170px;" cellspacing="0" cellpadding="0" bordercolor=#000000 border="1" bgcolor=#FFFFFF><tr><td>';
$res_banners = @mysql_query("SELECT * FROM `scbuttons` where `status`=1 and `max` > `shown` ORDER BY RAND() LIMIT 1");
while($banners = @mysql_fetch_array($res_banners)) {
mysql_query("update scbuttons set shown=shown+1, show_views=show_views+1 where id=".$banners['id']);
if ($banners['bannerurl'] != "" ) {
	if( session_is_registered("ulogin") ) {
		echo '<marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
		<a href="' . $domain . '/scbuttonclick1.php?id="' . $banners['id'] . '" target="_blank">
		<img src="' . $banners['bannerurl'] . '" style="float:left;" border="0" />
		</a>
		</marquee>';
	} else {
		echo '<marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
		<a href="' . $domain . '/scbuttonclick.php?id="' . $banners['id'] .'" target="_blank">
		<img src="' . $banners['bannerurl'] . '" style="float:left;" border="0" />
		</a>
		</marquee>';
	}
}
}
echo '</tr></td></table></center>';
?>

Now that I look a little more closely at this, there are a couple other things that could use tweaking. session_is_registered() is deprecated, so that should be changed to if( isset($_SESSION['ulogin']) ) {

 

But the one thing that really stands out is that no matter if the session var is set or not, the result is the same, making the if/else statement pointless. What is supposed to happen if the $_SESSION['ulogin'] var is not set?

Now that I look a little more closely at this, there are a couple other things that could use tweaking. session_is_registered() is deprecated, so that should be changed to if( isset($_SESSION['ulogin']) ) {

 

But the one thing that really stands out is that no matter if the session var is set or not, the result is the same, making the if/else statement pointless. What is supposed to happen if the $_SESSION['ulogin'] var is not set?

 

if it's not set it will change the clickable hyperlink attached to the banner with a different one that is for non-members.

i really appreciate ur help. i used ur edited code but it's still not showing beside each other. it's still going over each other.

let me know if u need another snapshot of how it looks now.

Oh, OK. That makes sense now. Anyhow, I overlooked the <marquee></marquee> tags. i moved those out of the loop, and it should work properly this time :)

 

<?php
echo '<center><table style="width:800; height: 170px;" cellspacing="0" cellpadding="0" bordercolor=#000000 border="1" bgcolor=#FFFFFF><tr><td>
<marquee behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">';
$res_banners = @mysql_query("SELECT * FROM `` where `status`=1 and `max` > `shown` ORDER BY RAND() LIMIT 1");
while($banners = @mysql_fetch_array($res_banners)) {
mysql_query("update scbuttons set shown=shown+1, show_views=show_views+1 where id=".$banners['id']);
if ($banners['bannerurl'] != "" ) {
	if( session_is_registered("ulogin") ) {
		echo '<a href="' . $domain . '/scbuttonclick1.php?id="' . $banners['id'] . '" target="_blank">
		<img src="' . $banners['bannerurl'] . '" style="float:left;" border="0" />
		</a>';
	} else {
		echo '<a href="' . $domain . '/scbuttonclick.php?id="' . $banners['id'] .'" target="_blank">
		<img src="' . $banners['bannerurl'] . '" style="float:left;" border="0" />
		</a>';
	}
}
}
echo '</marquee></td></tr></table></center>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.