July 12, 201115 yr Ok, so I have noticed something I never noticed before with MySql arrays in php, returned by mysql_query. I was just using this snippet of code to look at the complete structure of the MySql array, $result = mysql_query("SELECT * FROM test.$tableName") or die(mysql_error()); $row = mysql_fetch_array($result); echo "<pre>"; print_r($row); I was expecting to see an array like Array ( [id] => 2 [title] => IS Staff Induction [course_date] => 2010-05-13 [start_time] => 09:30:00 [end_time] => 12:30:00 [availability] => 5 [location] => ) but instead got Array ( [0] => 2 [id] => 2 [1] => IS Staff Induction [title] => IS Staff Induction [2] => 2010-05-13 [course_date] => 2010-05-13 [3] => 09:30:00 [start_time] => 09:30:00 [4] => 12:30:00 [end_time] => 12:30:00 [5] => 5 [availability] => 5 [6] => [location] => ) now why is there duplication of the data with a numerical index and an index of the MySql field name? Is there a way to stop this behaviour and return just the data, indexed by field name? Thanks!! Edited July 12, 201115 yr by frupence
July 12, 201115 yr mysql_fetch_array() gives you results based on the column title and its index in the order of fields. If you just want the associative names, use mysql_fetch_assoc() instead
Create an account or sign in to comment