Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/50484-help-with-images/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/50484-help-with-images/#findComment-248197
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.