44justin Posted May 8, 2007 Share Posted May 8, 2007 hello dear phpers i have a problem i can;t solve and i hope you people can help me i have a banner rotate system with a code that is this: ::::: code :::::: <? $rs_t=mysql_fetch_array(mysql_query("select count(*) from sbwmd_ads where paid='yes' and credits>displays")); $cnt= $rs_t[0]; if ($cnt==0) { echo "<a href='advertise.php'><img src='images/default_banner.gif' width= height=100 border=0></a>"; } else { $rs_t_query=mysql_query("select * from sbwmd_ads where paid='yes' and credits>displays"); $rnum=abs( mt_rand(1,$cnt) ) ; for ($i=0;$i<$rnum;$i++) { $rs_t=mysql_fetch_array($rs_t_query); } $id=$rs_t["id"]; $url=$rs_t["url"]; $bannerurl=$rs_t["bannerurl"]; echo "<a href='$url'><img src='$bannerurl' width=400 height=100 border=0></a>"; mysql_query("update sbwmd_ads set displays=displays+1 where id=$id"); } ?> i ahve used that script twice in one php document but the problem is that sometimes the 2 banner spaces show the same images is there a script or code that makes it so they dont show the same image ((the 2 places take the images frome the same database))) 44justin Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/ Share on other sites More sharing options...
suzzane2020 Posted May 8, 2007 Share Posted May 8, 2007 if u have stored the image names in te database, try using the keyword DISTINCT in ur mysql query. distinct(image) Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248026 Share on other sites More sharing options...
44justin Posted May 8, 2007 Author Share Posted May 8, 2007 can u maybe explain that Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248030 Share on other sites More sharing options...
suzzane2020 Posted May 8, 2007 Share Posted May 8, 2007 ok In the query you use to get the images from the databse; include a keyword DISTINCT for eg: select distinct(image),and all the other fields u want from tblname" that way when u use distinct, images with the same name or url wud not appear I hope u gt it Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248037 Share on other sites More sharing options...
44justin Posted May 8, 2007 Author Share Posted May 8, 2007 no i not get is can u maybe use the codes in my sournce i dont get it at all ??? Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248089 Share on other sites More sharing options...
Rottingham Posted May 8, 2007 Share Posted May 8, 2007 no i not get is can u maybe use the codes in my sournce i dont get it at all ??? This is definately not an english/grammar forum! If it was I'd go batty. However, TRY THIS code in your script... Replace: $rs_t_query=mysql_query("select * from sbwmd_ads where paid='yes' and credits>displays"); With this $rs_t_query=mysql_query("select *, DISTINCT('bannerurl') from sbwmd_ads where paid='yes' and credits>displays"); This makes it only pull banner ads that do not have the same name, so if you were looping through the results, you would make sure not to get the same database row twice. However, this is not the solution for your problem. What you need to do is save the 'bannerurl' in a global, such as $_SESSION[] superglobal... like so... $_SESSION["last_bannerurl"]; Now, ever time you run your script to get a banner, add this conditional to your script: $rs_t_query=mysql_query("select * from sbwmd_ads where paid='yes' and credits>displays"); $rnum=abs( mt_rand(1,$cnt) ) ; for ($i=0;$i<$rnum;$i++) { $rs_t = mysql_fetch_array($rs_t_query); // THIS IS THE ADDED CONTITIONAL if(strcmp($rs_t["bannerurl"], $_SESSION["last_bannerurl"])) continue; // Skip this iteration } $id=$rs_t["id"]; $url=$rs_t["url"]; $_SESSION["last_bannerurl"] = $bannerurl = $rs_t["bannerurl"]; I will not, that you FOR loop makes absolutely no sense... you are just looping and assinged the sql result to a variable over and over again... Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248197 Share on other sites More sharing options...
44justin Posted May 8, 2007 Author Share Posted May 8, 2007 thanks it works fine but there is only 1 thing sometimes 1 banner ads shows nothing ( www.zondata.com ) sometimes 1 banner spaces show no banner Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248239 Share on other sites More sharing options...
44justin Posted May 8, 2007 Author Share Posted May 8, 2007 ??? can anyone help with my problem Quote Link to comment https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248320 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.