Jump to content

Noob- Please help a sista out!!!


MishelM

Recommended Posts

Ok I am trying to rotate ads on a page ( no big deal.. very simple ad rotation script) HOWEVER how do I ensure that the same ads do not show on the same page?  What would I need to ad to the following code?

 

I am using this code between <head> and </head>

 

<script type="text/javascript">

function reload() {

window.location.reload();

}

function countdown() {

setTimeout("reload()", 10000);

}

</script>

 

Then I am using this in the individual ad placement slots

 

<?php

include("config.php");

$random = rand(0, count($image)-1);

echo "<p><a href=\"" . $link[$random] . "\"><img src=\"" . $image[$random] . "\" border="0" /></a></p>";

?>

 

 

Then I have aconfig.php file which looks like this

 

<?php

$image[0] = "Ads/Ad_01.jpg";

$link[0] = "http://www.mysite.org/myproduct";

$image[1] = "Ads/Ad_02.jpg";

$link[1] = "http://www.mysite.org/myproduct";

?>  ( there are more links but you get the drift)

 

 

Is there anyone that can help me- I am a beginner so be gentle!!!! :shy:

Link to comment
Share on other sites

Try moving this to the top of your PHP page:

<?php require_once("config.php"); ?>

 

And put this in your advertisement areas:

<?php
$random = rand(0, count($image)-1);
echo "<p><a href=\"" . $link[$random] . "\"><img src=\"" . $image[$random] . "\" border="0" /></a></p>";
unset($link[$random], $image[$random]);
?>

 

I think that'll do it for you.  It's not an optimal solution, but it's the easiest.

 

By the way, there's tons of room for improvement here.  You should look into associative arrays and the array_rand function.

Link to comment
Share on other sites

  • 4 weeks later...

A rough idea...

 

/* first put all your ads into an array */
/* for example */

$my_ads = array("image1.jpg", "image9.jpg", "imageabc.jpg", "image_me.jpg", "imagew.jpg", "imagede.jpg", "image01.jpg", );

/* shuffle the array */
$my_ads = shuffle($my_ads);

/* display the first element and remove it from the array */
/* repeat this step as often as necessary */
/* NOTE: make sure you only do it as often as there are still ads in the array */

$what_ad = array_shift($my_ads);

echo $what_ad;

Link to comment
Share on other sites

Ok here is what I am using in the individual ad slots right now- ( see below)  would I place  $random+1 in the place I have highlighted in bold?  If I had four slots would I use +1, +2 etc ?  Sorry for being so thick but this is all pretty new to me.  I really appreciate the help!!

 

 

<?php $random = rand(0, count($image)-1);

 

echo "<p><a href=\"" . $link[$random] . "\"><img src=\"" . $image[$random] . "\" alt=\"My affiliate\" /></a></p>";

 

?>

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.