Jump to content

Assigning one query results to two variables.


iarp

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.