00stuff Posted October 26, 2012 Share Posted October 26, 2012 Hi, I am trying to create an array from a mysql query that looks like this. $people = array( "8776546543" => "John Smith", "8779876543" => "John Dow", ); I need for that array to come from two columns of a mysql query and be placed on the $people variable. I am not sure how to do it. Can some one help me please? Quote Link to comment https://forums.phpfreaks.com/topic/269925-creating-an-array-from-a-mysql-query/ Share on other sites More sharing options...
Pikachu2000 Posted October 26, 2012 Share Posted October 26, 2012 Take this logic and apply it to your code. $your_array = array(); while( $array = mysql_fetch_assoc($result) ) { $your_array[$array['first_field']] = $array['second_field']; } Quote Link to comment https://forums.phpfreaks.com/topic/269925-creating-an-array-from-a-mysql-query/#findComment-1387821 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.