Jump to content

Multiple while($r=mysql_fetch_array) loops not working!


Avalanche

Recommended Posts

Hello.

 

Near the top of my code, I have a:

 

[php:1:b3f9f9e1f6]while($r=mysql_fetch_array($query_events)) { // cycle through events

// soon to be code here

}[/php:1:b3f9f9e1f6]

 

(the $query_events has already been defined)

Then, on a lower part of my code I have another:

 

[php:1:b3f9f9e1f6]while($r=mysql_fetch_array($query_events)) { // cycle through events

// lots of code here

}[/php:1:b3f9f9e1f6]

 

For some reason the first one will work, but not the second one.

 

Any reason why this might be happening?

 

Thanks.

Link to comment
Share on other sites

Okay... well it seems if I display only one of those two at the top, then it will only display the other of the two on the bottom.

 

Basically, once I select it from the database it won\'t let me select it again... is there any way to, uh... unselect it after you\'re done or something?

 

Thanks.

Link to comment
Share on other sites

is $query_events being redefined between the two code snippets?

 

if its not, and you are working on the same result set, then the first while loop exhausts the query results, and the second one will never be true and will not run.

 

you will have to either store the results within your first qry in an array or whatever you choose, or run the query again to get the result set. Id advocate the first choice.

Link to comment
Share on other sites

Yes it would work. But you could also just execute the query again, with a mysql_query call. You need a query to get a result set. Once the result set has been fetched, as was stated, it\'s basically useless.

 

If this is any static value, the advice of loading it into an array is a very good one. If you can avoid doing a requery you\'re keeping load off the database, and it should also perform better. If you are changing the database, or have an expectation that it might have changed then the re-query is understandable.

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.