Avalanche Posted July 12, 2003 Share Posted July 12, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/ Share on other sites More sharing options...
effigy Posted July 13, 2003 Share Posted July 13, 2003 hm. how many rows does that query return? Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2347 Share on other sites More sharing options...
Avalanche Posted July 13, 2003 Author Share Posted July 13, 2003 Only two... I still can\'t figure it out. Want my entire page code? Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2348 Share on other sites More sharing options...
Avalanche Posted July 13, 2003 Author Share Posted July 13, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2350 Share on other sites More sharing options...
dammitjanet Posted July 13, 2003 Share Posted July 13, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2351 Share on other sites More sharing options...
Avalanche Posted July 13, 2003 Author Share Posted July 13, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2352 Share on other sites More sharing options...
gizmola Posted July 13, 2003 Share Posted July 13, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/711-multiple-whilermysql_fetch_array-loops-not-working/#findComment-2353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.