building - How do I populate and associative array using php and mysql -


how add elements below array?

/// build cross reference array parent company names of subcategories///

$newarray = array(); $comp_names = "select company_name, company_id pe_company_access"; $name_results = mysql_query($comp_names, $dbcnx);  while ($row5 = mysql_fetch_assoc($name_results))  {     $newarray = array($row5["company_id"] => $row5["company_name"]);  }  print_r($newarray); 

thanks, george

i say, should go with:

while ($row5 = mysql_fetch_assoc($name_results))  {     $newarray[$row5["company_id"]] = $row5["company_name"]; } 

that way have company_id key of associative array, , company_name value. if want have sub arrays, indexed 0 based index, need following:

while ($row5 = mysql_fetch_assoc($name_results))  {     $newarray[] = array($row5["company_id"] => $row5["company_name"]); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -