rwilkerson Posted May 1, 2007 Share Posted May 1, 2007 I have a situation where I need to retrieve a set of records from a MySQL DB and, rather than display those results, reformat the resultset to JSON and return it to a calling page. Ideally, I'd like to simply fetch an array of all results (an array of associative arrays), wrap it in json_encode() and go on my way. Not only can I not find anything that tells me how to do it, I can't even seem to find anything that definitively tells me whether it's *possible*. Initially, I tried this: json_encode ( mysql_fetch_assoc ( $myresult ) ) But that only encodes the first record. Can anyone lend me their PHP experience? I haven't yet learned its ins and outs. Thanks. Rob Link to comment https://forums.phpfreaks.com/topic/49455-retrieving-entire-resultset-from-mysql/ Share on other sites More sharing options...
veridicus Posted May 1, 2007 Share Posted May 1, 2007 $data = array(); while ($record = mysql_fetch_assoc($myresult)) { $data[] = $record; } $data will contain the entire result set. Link to comment https://forums.phpfreaks.com/topic/49455-retrieving-entire-resultset-from-mysql/#findComment-242395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.