phpmady Posted April 8, 2012 Share Posted April 8, 2012 Hi, I need to create a array like below, from the table: $items = array( "Great <em>Bittern</em>"=>"1", "Little <em>Grebe</em>"=>"2", "Little <em>Grebe</em>"=>"3", "Little <em>Grebe</em>"=>"4" ); users table has 2 columns: id name Thanks, Mubarak.A Quote Link to comment https://forums.phpfreaks.com/topic/260548-creating-arrays-from-the-rable/ Share on other sites More sharing options...
trq Posted April 8, 2012 Share Posted April 8, 2012 And your problem is? Quote Link to comment https://forums.phpfreaks.com/topic/260548-creating-arrays-from-the-rable/#findComment-1335339 Share on other sites More sharing options...
phpmady Posted April 10, 2012 Author Share Posted April 10, 2012 Hi, I tried to create a array, with the following php code, but am failed whats wrong am doing here? $query = "SELECT user_id,f_name FROM user_profile"; $result = mysql_query($query); echo $result; while ($row = mysql_fetch_array($result)) { $results['f_name'] = $row['user_id'] ; } Quote Link to comment https://forums.phpfreaks.com/topic/260548-creating-arrays-from-the-rable/#findComment-1336059 Share on other sites More sharing options...
dcro2 Posted April 10, 2012 Share Posted April 10, 2012 'f_name' is still part of the $row array even if you use it like that, so this would work: $results[$row['f_name']] = $row['user_id']; Quote Link to comment https://forums.phpfreaks.com/topic/260548-creating-arrays-from-the-rable/#findComment-1336062 Share on other sites More sharing options...
chriscloyd Posted April 10, 2012 Share Posted April 10, 2012 <?php $query = "SELECT user_id,f_name FROM user_profile"; $result = mysql_query($query); echo $result; $results = array(); while ($row = mysql_fetch_array($result)) { $results[$row['f_name']] = $row['user_id'] ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260548-creating-arrays-from-the-rable/#findComment-1336253 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.