View Full Version : Anyone Know How I COuld Get This To Display Randomly???

03-17-2003, 01:20 AM
well i want a diffrent poll to [pop up each tim but unfortunatly i have to add this for each one to show..
<?php require '/home/stoodder/public_html/myweb6/polls/booth.php';
display_booth(1); ?>
<?php require '/home/stoodder/public_html/myweb6/polls/booth.php';
display_booth(2); ?>

anyone know how i can make the 1 or 2 change randomly??

03-17-2003, 01:40 AM
Use the rand (http://php.net/rand) function

$poll1 = '1';
$poll2 = '2';

$poll = rand($poll1,$poll2);

require '/home/stoodder/public_html/myweb6/polls/booth.php';

03-17-2003, 03:01 AM
oo thank you havent learned the rand function yet im just learning how to write and update files and stuff so thank you that will really help with the random file thing also

one last question could i make i

$poll1 = "1";
$poll2 = "2";
$poll3 = "3";
$poll = rand($poll1, $poll2, $poll3);

03-17-2003, 08:46 AM
rand randomly picks numbers from one value to the next, so rand($poll1,$poll3) would pick poll1 - poll3 randomly.

03-17-2003, 03:29 PM
ahh ic i also to the liberty to make it use arrays now... i think it is more secure lol im not sure im to new oh well heres what i have:

$poll[1] = '1';
$poll[2] = '2';
$poll[3] = '3';

$i = rand(1, sizeof($poll));
require 'polls/booth.php';
&displey_booth = ($poll[$i]);

lol sorry i just learned the sizeof thing also and the floor wich rounds down.. i wonder if ceiling rounds up *goes off to try*

03-17-2003, 03:51 PM
array_rand() would be a better way of doing that.

$a = array('1','2','3','7');
$b = array_rand($a);

would make $b a random choice from all the array values.