Jump to content

help with images


44justin

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

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.