| Get an array from a SQL database column
|
moivreus

msg:4099946 | 10:47 pm on Mar 17, 2010 (gmt 0) | Hi all, I'm new to php so I encounter problems which some of you might not find as such. For example: I have a db with a table with only 2 columns: id & category, so the data flows as: "1, 2, 3..." and "category1, category2, category3..." And I want to get an array that looks like: $array1 = array(category1, category2, category3...) , basically containing all the values from the "category" column. How do I do that with PHP and MYSQL?
|
gsmith

msg:4099967 | 11:13 pm on Mar 17, 2010 (gmt 0) | Surely there must be more elegant ways of doing this, but you can store the values in a varchar field like this [1,2,3] (i.e. comma seperated), and execute code like this after reading that field: eval( '$myArray = array(' . $row["myField"] . ');' );
|
Readie

msg:4100004 | 12:00 am on Mar 18, 2010 (gmt 0) | This might be what the OP is after: [uk2.php.net...]
|
moivreus

msg:4100066 | 2:56 am on Mar 18, 2010 (gmt 0) | thanks Readie, I didn't understand why the result from mysql_fetch_row doesn't act as a proper array until I discovered that it should be flatten first. to gsmith: thanks for the answer, but it's way too advanced for me [edited by: moivreus at 3:01 am (utc) on Mar 18, 2010]
|
|
|