Jump to content

Archived

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

Avalanche

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

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.

Share this post


Link to post
Share on other sites

hm. how many rows does that query return?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hmm... what if I had two indentical queries, but with different names? Would that work (I would test it, but I\'m not on my PC that I use for PHP)?

 

Thanks once again, I very much appreciate it.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.