Randomize/Group/Paste
Posted: Tue Jul 29, 2003 11:47 pm
I currently have a PHP script that takes a name that was typed into a textbox and adds it to a MySQL server. Its setup to only accept 24 names for my purpose. When the names are in the server, id like it to randomize the names and place them into 8 groups of 3, adding those groups to a webpage, i have tried something like this, but failed w/o luck
ruc_players being the sub db of the db. ideas or help greatly appreciated
Code: Select all
<?php
mysql_connect("dbhost", "dbusername", "dbpassword");
$db = mysql_select_db("dbname");
$result = mysql_query("SELECT name FROM ruc_players");
$arr = mysql_fetch_array($result, MYSQL_NUM);
srand((float)microtime()*1000000);
shuffle($arr);
$team = 1;
while (count($arr) > 0)
{
$name = array_pop($arr);
mysql_query("UPDATE ruc_players SET team='$team' WHERE name='$name'");
$team = (($team == 7) ? 1 : $team + 1);
}
?>