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
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]

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

That actually raises another question. The query should only selecting 1 graphic, but it sounds like there is more than 1 displaying on your page. Is that correct?

yes, i put the limit only when i couldn't display it right. but it should display at least 10.

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.