nomanoma Posted June 25, 2010 Share Posted June 25, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/ Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 The method of data retrieval from the database should have nothing to do with the manner in which it's displayed. Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077314 Share on other sites More sharing options...
nomanoma Posted June 25, 2010 Author Share Posted June 25, 2010 ok can u please tell me how to display the banners side by side and not over each other ? Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077331 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077355 Share on other sites More sharing options...
nomanoma Posted June 25, 2010 Author Share Posted June 25, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077363 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077380 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077391 Share on other sites More sharing options...
nomanoma Posted June 25, 2010 Author Share Posted June 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077438 Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2010 Share Posted June 26, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077442 Share on other sites More sharing options...
nomanoma Posted June 26, 2010 Author Share Posted June 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077445 Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2010 Share Posted June 26, 2010 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077447 Share on other sites More sharing options...
nomanoma Posted June 26, 2010 Author Share Posted June 26, 2010 wow thank u ) u r awesome. i can't believe i was that stupid how can i repay you??? Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077454 Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2010 Share Posted June 26, 2010 It wasn't stupid. Don't forget, I missed it too! You can "repay" me by helping another person here sometime, if you get the chance. Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077455 Share on other sites More sharing options...
nomanoma Posted June 26, 2010 Author Share Posted June 26, 2010 well, thank u so much again. of course i'll do my best to help around here. and if u ever need anything u can pm me Quote Link to comment https://forums.phpfreaks.com/topic/205869-horizontal-scrolling-banners/#findComment-1077457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.