Jump to content


Complex Query - Rebuilding the Facebook Wall


1 reply to this topic

#1 Blambu

    Young Padawan

  • Members
  • Pip
  • 17 posts

Posted 14 November 2009 - 12:54 PM

Hi guys,

I have a pretty complex question - Well at least I think it might be.

What I have is a "wall" type of area on my users profile, however, on the wall I want things such as statuses, and wall posts and any other set material to show up on there in order of latest published.

I have a wall and statuses table, containing necessary fields to show them by themselves. Both tables have date_posted columns.

Now the question is "How can I list ALL statuses and wall posts by that user ordered by the latest published?"

If anyone can help me this, this would be highly appreciated.

I'm sort of thinking creating another table .. That will hold IDs for wall posts and statuses, and their dates then query that table. But that would require running two queries when inserting something. Or is this better?


Appreciate any help.

Jamie

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 14 November 2009 - 04:21 PM

Since it doesn't sound like the wall/statues table have a 1:1 relationship i don't think you can do a JOIN of anysort. The next most likely bet would be a UNION, but that also has some complications (not to mention i don't think you can do an ORDER BY after the UNION). If the tables are union compatable, you could probably make a view, which could aleviate the need for an additional table. Though, if you can arrange it, two inserts would probably be better than my next alternative:

Use 2 selects, then build up an array of the entries you want displayed, and find a way to sort the array by the date. Since i don't know how you will build up the array, here are two sort functions you could look at:
http://php.net/manua...ction.asort.php (the indexes of the array would be the dates, be careful to check for duplicate dates).
http://php.net/manua...ction.usort.php (the date would be somewhere in the array itself)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users