RIRedinPA Posted November 23, 2010 Share Posted November 23, 2010 If I have a db with these fields: displayname, title and I run a successful query on the db, will this code: if (mysql_num_rows($results) == 0) { return "!fail"; } else { while ($row = mysql_fetch_assoc($results)) { extract($row); } return $row; } create an associative array of $var = array(array('displayname' => value, 'title' => value), array('displayname' => value, 'title' => value)...) If not, is there a way to do so, especially when I will not know the names or number of fields in a db table? Link to comment https://forums.phpfreaks.com/topic/219604-make-assoc-array-from-query-results/ Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 This should work for ya. $var = array(); while ($row = mysql_fetch_assoc($results)) { $var[] = $row; } Link to comment https://forums.phpfreaks.com/topic/219604-make-assoc-array-from-query-results/#findComment-1138556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.