Create an associative array from table
Posted: Thu May 15, 2008 4:14 pm
I am trying to create an associative array reading fields tag & count from a table named tags.
Doing it manually, I would use:
I have tried looping through the table as follows:
Any assistance would be greatly appreciated - this is driving me crazy!!! Thanking you in advance...
Doing it manually, I would use:
Code: Select all
/* array of items and sizes
$tagArray = array(
"Apple" => 9,
"Cell Phone" => 12,
"Computer" => 6,
"eBay" => 1,
"Gadget" => 3
);Code: Select all
$query = mysql_query("SELECT * FROM tags ORDER BY count DESC");
// loop through table world counting occurrences of parent
while ($row = mysql_fetch_array($query)) {
$tagArray [$tag] = $count; // tried this and several other variations with no success
}