Jump to content


PHP Random


7 replies to this topic

#1 Andy

    Graphical Idol Judge

  • Members
  • PipPipPip
  • 594 posts
  • Gender:Male
  • Location:Yorkshire, UK

Posted 13 November 2004 - 12:36 PM

Heres my problem,

<?
$banner[] = "<a href=\"http://stealthdesignz.com\" target=\"_blank\">number one</a>";
$banner[] = "<a href=\"http://stealthdesignz.com\" target=\"_blank\">number two</a>";
echo $banner[array_rand($banner)]; ?>  

This will keep giving me the same result, over and over again.... i see no problem with the code though :S

Andy

#2 Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 13 November 2004 - 12:50 PM

Try adding 4 or 5 useless entries and see if they ever show up. I've noticed that even with the random value, the first entry always shows up more than the others, I don't know why though....

I think its a probability thing, with 2 entries there's a 50/50 chance it'll pick one, but its random so it could pick each one 10 times in a row, you never know. The more entries there are, the more truely random it is...

Edited by Jaymz, 13 November 2004 - 12:51 PM.


#3 Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 13 November 2004 - 08:01 PM

Your using the randomization tutorial from ethics designs I see. Their ending code looks like this

<?
$banner[] = "<a href=\"URL\" target=\"_blank\"><img src=\"IMAGE\" alt=\"\" border=\"0\" width=\"88\"
height=\"31\"></a>";
$banner[] = "<a href=\"URL\" target=\"_blank\"><img src=\"IMAGE\" alt=\"\" border=\"0\"></a>";
echo $banner[array_rand($banner)];
?>

Are you including this onto a page? Because it sais to do so in their tutorial I would do something like this.

<?
$banner[] = "<a href=\"URL\" target=\"_blank\"><img src=\"IMAGE\" alt=\"\" border=\"0\" width=\"88\"
height=\"31\"></a>";
$banner[] = "<a href=\"URL\" target=\"_blank\"><img src=\"IMAGE\" alt=\"\" border=\"0\"></a>";
echo $banner[array_rand($banner)];

Then

<?
include "file.php"

echo $banner[array_rand($banner)];
?>


#4 Andy

    Graphical Idol Judge

  • Members
  • PipPipPip
  • 594 posts
  • Gender:Male
  • Location:Yorkshire, UK

Posted 14 November 2004 - 12:42 PM

Nono, someone juts gave me the code over AIM... then left... :\
ill try it your way and see what happens :P

Andy

**EDIT** Nop... this also doesnt work and displays the second result

#5 Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 14 November 2004 - 07:52 PM

Hmm... well the code is basically the same, whoever gave you that code used that tutorial/

#6 Andy

    Graphical Idol Judge

  • Members
  • PipPipPip
  • 594 posts
  • Gender:Male
  • Location:Yorkshire, UK

Posted 15 November 2004 - 11:46 AM

Maybe so... i the tutorial isnt all that.. great :yoda:

I might get some other people to try it out later, see what happens to them :|

Andy

#7 Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 15 November 2004 - 05:40 PM

Why not use my affiliates tutorial? If ya want I can help you out with it.

#8 Andy

    Graphical Idol Judge

  • Members
  • PipPipPip
  • 594 posts
  • Gender:Male
  • Location:Yorkshire, UK

Posted 16 November 2004 - 11:16 AM

I have a random affiliate script already.. the problem is only that i get repeateed and duplicated affiliates when i display... i.e - 6

The one i got now is fine, i have so many affiliates... noone really notices anymore. But, i need one that isnt mysql anyway.... cos..... my site just isnt mysql runned:\

Andy





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users