Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Anyone Know How I COuld Get This To Display Randomly???

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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use the rand function
    PHP Code:
    <?php
    $poll1 
    '1';
    $poll2 '2';

    $poll rand($poll1,$poll2);

    require 
    '/home/stoodder/public_html/myweb6/polls/booth.php'
    display_booth($poll); 
    ?>
    Last edited by Nightfire; 03-17-2003 at 12:43 AM.

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

    PHP Code:
    <?php
    $poll1 
    "1";
    $poll2 "2";
    $poll3 "3";
    $poll rand($poll1$poll2$poll3);
    Last edited by stoodder; 03-17-2003 at 02:19 AM.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    rand randomly picks numbers from one value to the next, so rand($poll1,$poll3) would pick poll1 - poll3 randomly.

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:
    PHP Code:
    <?php
    $poll
    [1] = '1';
    $poll[2] = '2';
    $poll[3] = '3';

    $i rand(1sizeof($poll));
    floor($i);
    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*

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •