iarp Posted August 17, 2012 Share Posted August 17, 2012 I'm trying to limit the number of calls on the database I must make. I have one that returns approx 4000 rows. I'm needing to use the results in two separate while loops, without making two calls resulting in 8000 rows being passed. I've tried just an easy [below], which didn't work, the second while loop didn't echo anything and didn't even error at all. $results = $results2 My guess as to why that happened would be because the first $result emptied the dataset and the $results2 was acting like a pointer or something, i'm not sure, completely speculating. Link to comment https://forums.phpfreaks.com/topic/267248-assigning-one-query-results-to-two-variables/ Share on other sites More sharing options...
Psycho Posted August 17, 2012 Share Posted August 17, 2012 Well, you can set the pointer back to the beginning [mysql_data_seek()] and run through the results again or just use a for type loop on the results set twice using an incrementing index to select the appropriate row [mysql_result()]. But really there is no need and would be inefficient. Just run the loop once and perform both sets of operations. If you are outputting data for those two operations, just assign the output content to variables and then output the variables later. Link to comment https://forums.phpfreaks.com/topic/267248-assigning-one-query-results-to-two-variables/#findComment-1370353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.