SQL query to array?
| From: | William Stokes | Date: | Wed, 26 Apr 2006 06:39:45 +0000 |
| Subject: | SQL query to array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-234776@lists.php.net to get a copy of this message | ||
Hello,
Can someone please help me to put the results of a query to an array. Never
done this before:
$sql = "SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri
ASC";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$cur = 1;
//create empty array that contains an array before loop
$arr = array("Team" => array());
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$id = $row["jouk_id"];
$srt = $row["sortteri"];
$nimi = $row["jouk_nimi"];
//append values to the array
$arr = array("Team$cur" => array(0 => $id, 1 => $srt, 2 => $nimi));
$cur++;
}
Thanks
-Will