Jump to content

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.

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.