Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: Randomize and Group

    I was wondering how I could go about randomizing records in my database. I intend to get 24 records from the user, in which all of them will be added into the database, with an ID# (according to when they were entered). After I get the 24 records, I would like to "randomize" them in my database.

    for example.

    ID | Name
    --------------
    1 John
    2 Fred
    3 Joe
    .. .... (etc)

    Is how my table would look, all the way down to 24. After that, I would like to be able to randomize them, when I click on a button (action = randomize.php). When complete, the table should look like..

    ID | Name
    --------------
    2 Fred
    3 Joe
    1 John
    .. .... (etc)

    Something to that effect.

  2. #2
    Join Date
    May 2004
    Posts
    2
    Ok, if no one will answer.. I'll answer it myself.

    PHP Code:
    <?php

    // Connect to the database so we can use it, doi.
    mysql_connect("localhost","user","pass");

    // SELECT the database that were gonna need.
    mysql_select_db("thedb");

    // Make an array to hold every users name, and set our counter at 1
    $usersArray[24];
    $t 1;

    // Define our query that will be used, and the result
    $query "SELECT * FROM users";
    $result mysql_query($query);

        
    // Keep on chuggin' through the table until we've gone through the whole thing
        
    while($row mysql_fetch_array($result)) {
            
    // Store the name that were currently on, in the array
            
    $usersArray[$t] = $row["name"];
            
    // Increment t by 1.
            
    $t++;
        }
        
    // Clean up after were done! (We're polite, right?)
    mysql_free_result($result);

    ?>
    That'll take all the records of the database, and store them into an array. With that done, I can now easily randomize, and group them.

Posting Permissions

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