rvdb86 Posted August 20, 2012 Share Posted August 20, 2012 Hey guys, I am trying to perform a very simple select query from a MySql database, but for some reason the array that is returned contains duplicates. This is my code: $allData = mysql_query("SELECT * FROM table"); while($result = mysql_fetch_array($allData)){ echo "<pre>"; print_r($result); echo "</pre>"; } and my output looks like this: Array ( [0] => 62 [id] => 62 [1] => 502fa610b7856 [intID] => 502fa610b7856 [2] => 4c36fd909b37208b [location] => 4c36fd909b37208b [3] => obj2 [shoe] => obj2 [4] => how_to_use_with_back_displayed [action] => how_to_use_with_back_displayed [5] => 2012-08-18 17:26:22 [date] => 2012-08-18 17:26:22 [6] => 00:00:00 [duration] => 00:00:00 ) Why is it duplicating every column?? TIA! Quote Link to comment https://forums.phpfreaks.com/topic/267331-php-mysql-select-query-returning-duplicates-in-array/ Share on other sites More sharing options...
spiderwell Posted August 20, 2012 Share Posted August 20, 2012 you have not specified in mysql_fetch_array the result type, you have got in your instance MYSQL_BOTH so you get 2 of everything EDIT:: look it is all here: http://php.net/manual/en/function.mysql-fetch-array.php Quote Link to comment https://forums.phpfreaks.com/topic/267331-php-mysql-select-query-returning-duplicates-in-array/#findComment-1370784 Share on other sites More sharing options...
Barand Posted August 20, 2012 Share Posted August 20, 2012 ... or use mysql_fetch_row() or mysql_fetch_assoc() depending on whether you want column numbers or column names as the array keys. Quote Link to comment https://forums.phpfreaks.com/topic/267331-php-mysql-select-query-returning-duplicates-in-array/#findComment-1370787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.