Re: SQL query to array?
| From: | Jim Lucas | Date: | Wed, 26 Apr 2006 06:45:55 +0000 |
| Subject: | Re: SQL query to array? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-234780@lists.php.net to get a copy of this message | ||
William Stokes wrote:
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 You might try this as an alternative:$cur = 0; while (list($id, $srt, $nimi) = $mysql_fetch_array($result)) { $arr = array("Team{$cur}" => array(0 => $id, 1 => $srt, 2 => $nimi)); $cur++; } Jim