php + myql help

Discussion in 'PHP' started by cavendano, Nov 5, 2007.

  1. #1
    have a bit of a problem..right now I have this script randomly displaying site names that have registered on my site...the problem is the initial page url and the one that is later verified are different not because I want to but because anytime I call the variable at a later time it will spit something else out....how can i resolve this?
    // Edit this number to however many links you want displaying
    $num_displayed = 1 ;
    
    // Select random rows from the database
    $result = mysql_query ("SELECT * FROM users ORDER BY RAND() LIMIT $num_displayed"); 
    
    // For all the rows that you selected
    while ($row = mysql_fetch_array($result)) 
    
    {
    // Display them to the screen...
    
    
    $dadum = $row["site"];
    $datum = $row["id"];
    PHP:

     
    cavendano, Nov 5, 2007 IP
  2. iteamweb

    iteamweb Active Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    i cant understand what is the exact problem ..
    please be breif in what u say ..
    i am here to help php programmers
     
    iteamweb, Nov 5, 2007 IP
  3. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #3
    ok let me slow down a little bit...right now I am using a script that will display a site randomly using a variable like $dadum and check if it was stumbled...the problem is on the verification when I call $dadum at any other time it will change the site to a different random site so the verification will fail
     
    cavendano, Nov 6, 2007 IP
  4. garbageman

    garbageman Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's rather the intent of a random function... to be random.
    If you want your script to remember what specific site was chosen at random the first time, use a session variable to store it.
     
    garbageman, Nov 6, 2007 IP
  5. tonyrocks

    tonyrocks Active Member

    Messages:
    1,574
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    88
    #5
    yes, you need to store session variables to do this. ORDER BY RAND() clause will take random record every time the query is accessed.
     
    tonyrocks, Nov 6, 2007 IP
  6. GMROCKS

    GMROCKS Active Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #6
    if you want it to keep the same site, you have to do it inside of the for loop.
     
    GMROCKS, Nov 6, 2007 IP