tomdelonge Posted August 1, 2009 Share Posted August 1, 2009 So, i'm not great with arrays... I need this prototype: $data = array( '$row->id' => '$row->name' ); So, I would presume I need to loop over the result set and add each new line to the old array. How do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/168348-adding-data-to-an-array-from-a-result-set/ Share on other sites More sharing options...
Zane Posted August 1, 2009 Share Posted August 1, 2009 while($row = mysql_fetch_array($query)) { $data[$row['id']] = $row['name'] } Quote Link to comment https://forums.phpfreaks.com/topic/168348-adding-data-to-an-array-from-a-result-set/#findComment-888070 Share on other sites More sharing options...
fooDigi Posted August 1, 2009 Share Posted August 1, 2009 you could do something similar to this... $array = array(); while($row = mysql_fetch_array($mysql_result)) { $array[$row['id']] = $row['name']; } edit: oops, i see zanus has already posted the same... Quote Link to comment https://forums.phpfreaks.com/topic/168348-adding-data-to-an-array-from-a-result-set/#findComment-888072 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.