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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.