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? 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'] } 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... 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
Archived
This topic is now archived and is closed to further replies.