November 10th, 2012, 10:49 PM
Help with array from DB table
I am new to PHP and I may simply be overlooking something but i have the following code:
$query = "SELECT *
ORDER BY name ASC";
$content_set = mysql_query($query, $connection);
$content = mysql_fetch_array($content_set);
When i do the print_r i get this:
Array (  => 8 [id] => 8  => recruit [name] => recruit  => recruit [title] => recruit  => krisemp1 [supername] => krisemp1 )
which is a very jumbled version of what is in my database across multiple columns and rows.
Any advice on getting a clean array into my $content?
Or at least tell me what in the world its pulling?
November 11th, 2012, 04:56 AM
It's pulling the first row of the result set as an array with both numeric and string indices -- just like you told it to do.
Originally Posted by kirklogan
If you only want string indices, you have to pass MYSQL_ASSOC as the second parameter or instead use mysql_fetch_assoc().
By the way, using "SELECT *" is bad style, because you have no control over what it's actually selecting. Select specific columns.