This came straight out of the docs and it doesn't even work. It throws PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on the line "'one' => 1,"
What is wrong with how I am trying to do this loop??
Thanks,
Tom

$a = array(
   'one' => 1,
   'two' => 2,
   'three' => 3,
   'seventeen' => 17
);

foreach ($a as $k => $v) {
   echo "\$a[$k] => $v.\n";
}

Thomas Bolioli wrote:
I should add, it is not working with this funciton, which could be the source of the issue.

function dropbox_from_list($list, $selected_index){
   while ($nex = next($list)) {
       $k = key($nex);
       if (strcmp($selected_index, $k) == 0) {
           $select = ' SELECTED';
       }
       else {
           $select = '';
       }
       print("<option value='".$k."'".$select.">".$nex[$k]."</option>");
   }
}


Thomas Bolioli wrote:
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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to