If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Randomize and Group

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-04, 18:02
FrogXI FrogXI is offline
Registered User
 
Join Date: May 2004
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 05-30-04, 23:40
FrogXI FrogXI is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On