Jump to content

Recommended Posts

I guess the 'easiest' question, is can there be two "while" loops with a query?  I've looked that up and haven't really found a definite answer.  

 

 

I'm not looking for code to be written yet, just a push in a certain direction.  Here is what I'm looking for:

 

I'm separately wanting player names and if there are any events players play in.  Games are not treated as events, so not every row deals with an event.  Most will be games, especially this time of year.   Right now I'm adding a row or two each game about individual players.  The last "event" was in October.  The next "event" won't be until April.  In the spring and summer, there could be as many as 30-40 rows for a single event.     

 

 

So I want two lists on this one page view:

 

The most recent events information is posted on.

 

 

The most recent players information is posted on.  

 

 

The screenshot below is the current list, grouped by player name, listed alphabetically.  Above it, I'd like to have from the same data table a list of the most recent events.  

 

Is it just easier to do it with a separate query?  I might be complicating this, but I was once told on here not to query the same table on the same file.  

 

post-44159-0-79325900-1514382435_thumb.png

 

 

Link to comment
https://forums.phpfreaks.com/topic/306004-two-lists-for-one-query/
Share on other sites

Instead of doing a while loop that does a Fetch(), do a standalone FetchAll of the query results. That will move the results from a resource to a true array type and then you can do as many loops on that data as you want. Be sure to specify an Associated type of retrieval when you do the fetchall. (in pdo, that would be 'PDO::FETCH_ASSOC')

Running a second query to do your second task makes perfect sense of course. But - if you want to reduce resource usage and use the data in two different ways without re-generating the query results, what I gave you works just fine - assuming that you have made the proper query in the first place.

I just added a second query, and it worked.  Is there any reason why I shouldn't have two queries from the data table on the same page file?  It seemed like awhile ago (maybe even years ago) I was told not to do that.  

 

If the two queries are supposed to return a different result set, it would make sense. Your explanation was a little hard to follow. Some code on what you had/have might have been helpful. Whoever gave you that former advice either didn't know what they were talking about or they were talking about something quite different than what I think you were stating and you misinterpreted them.

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.