Jump to content

Can I prevent a query within a query??


dannyb785

Recommended Posts

I have a site with a facebook-type newsfeed and each newsfeed post has comments and likes.

 

So my code works like so:

 

*query that grabs all newsfeed posts

while(row = mysql_fetch_assoc())

{

  *query to grab this post's likes and output the number

  *query to gran this post's comments and output them

}

I have the proper columns indexed to help a little bit, but I feel helpless, is there a way to do anything close without having to do these queries within the main query?

Link to comment
https://forums.phpfreaks.com/topic/265732-can-i-prevent-a-query-within-a-query/
Share on other sites

I don't see why your not putting the "grabs newsfeed posts" and "grabs post's likes" in a single query - it would be a nested select but it would be tiny. In terms of nested loops which you'd have with the third query, why not retrieve all the data at the top of the page or where ever the logical place is for you, build a multidimensional array and cycle through the array as opposed to doing the queries on the fly sort of thing.

Archived

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

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