Associative array issues with loading values after initialization
| From: | Thomas Bolioli | Date: | Fri, 19 Sep 2008 16:49:09 +0000 |
| Subject: | Associative array issues with loading values after initialization | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-280528@lists.php.net to get a copy of this message | ||
The below function is not working.
function crm_get_country_list(){
global $dbh;
$result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error());
$country_list = array(' ' =>' ');
while ($row = mysql_fetch_assoc($result)){
$country_list[$row['pk_countryID']] = $row['country_name'];} return $country_list; } I know how to write this in perl but for some reason, when I write it in PHP it doesn't work. In perl it would be (roughly): function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); my %country_list; while ($row = mysql_fetch_assoc($result)){
$country_list[$row['pk_countryID']] = $row['country_name'];} return \%country_list; } What am I doing wrong here? Thanks in advance, Tom