Newbie question here... I'm sure it's so simple, but I'm getting a massive migraine from it.
I've got a MySQL database with this info in it:
Model Qty
--------------
1120-7 5
1120-2 23
2838-1 3
I want to assign this into an array out of the database as such:
$ytd = array ("1120-7" => "5", "1120-2" => "23 etc
I just can't figure it out. If I use mysql_fetch_assoc, I get $ytd[model]
If I use mysql_fetch_row and then a foreach loop, I can only pull out one element at a time and can't seem to assign them.
This is super easy I know... I just can't figure it out.
Also, as a side note and not important to this problem... the MySQL statement I'm using is "select model,sum(qty)..." When I use the fetch_assoc, it attempts to assign sum(qty) as $ytd[sum(qty)] but when I try do say print something like that ( print $ytd[sum(qty)] ) , I get an error.
I've got a MySQL database with this info in it:
Model Qty
--------------
1120-7 5
1120-2 23
2838-1 3
I want to assign this into an array out of the database as such:
$ytd = array ("1120-7" => "5", "1120-2" => "23 etc
I just can't figure it out. If I use mysql_fetch_assoc, I get $ytd[model]
If I use mysql_fetch_row and then a foreach loop, I can only pull out one element at a time and can't seem to assign them.
This is super easy I know... I just can't figure it out.
Also, as a side note and not important to this problem... the MySQL statement I'm using is "select model,sum(qty)..." When I use the fetch_assoc, it attempts to assign sum(qty) as $ytd[sum(qty)] but when I try do say print something like that ( print $ytd[sum(qty)] ) , I get an error.