|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Retrieve info from tables joined?
Please somebody can help me with? I am exhausted. I have been working on this query for 5 days, but haven's found a solution. Below is my db structure:
PHP Code:
1/ I am trying to query who last reply in each forum 2/ And I am trying to query who last post either reply or new thread. I know these are really hard questions. If anyone can help me I am greatly appreciative. Thank you all! |
|
#2
|
||||
|
||||
|
Just thinking out aloud here... something like (pseudo code ver):
select distinct forumid, max (replyid) inner join forum inner join thread inner join reply group by forumid Maybe if you added a date field to your 'reply' and 'thread' tables, you can use that to determine who posted last... (then again, you can also just use max(threadid/replyid)) |
|
#3
|
|||
|
|||
|
Thanks Stumpy!
Thanks you very much. But I have no idea how am I going to do it. I have no familiar with joining tables. Could you please go a littler detail so I can understand it.
This is my complete db structure: PHP Code:
What I would like to do is when the front page of the forum appeares it will list all the forums, aside of each forum I will see the 1/ Last Post (this column will show either Last Reply or Last Thread still count as Last Post) 2/ Last Reply 3/ Last Thread I believe that we have to use the $forumid to do the query. If I am wrong or not clearly post what I want to do, please let's me know. Thank you very much for you prompt respond. |
|
#4
|
||||
|
||||
|
If you don't have much experience with SQL, then I'd advise you to use some existing forum software - there are plenty of free, high quality forums available for all major languages. Most are easy to setup and customise, plus they have heaps of cool features that would normally take ages to write from scratch.
|
|
#5
|
||||
|
||||
|
BTW - you shouldn't use 'date' as a field name, as it is a reserved word. Any word that is used in the RDBMS (e.g. date, int, join, plus many more) should not be used as field names, as you will run into problems when forming your queries.
|
|
#6
|
|||
|
|||
|
Anyway, thanks Stumpy. The advice you gave me I would very much appreciate. I know there are lots of free forums out there they are free to use but the thing is I am working on this project for almost 2 months now, from the ground 0 up to this point. The forum is just a part of my project. There are only two things in the forum that I am having problem with is to query the Last Reply and Last Post, the rest of them I have already accomplished. With the helps of others this problem will be solved soon, without I will solve it myself. Thanks!
|
|
#7
|
|||
|
|||
|
Hey wareseeker,
Just as an FYI, I know some open source forums, specifically Snitz, store the ID of the last post author and date of the Last Post as fields in what would be your "thread" table. They probably do it to avoid some of the tortorous joins.. |
|
#8
|
|||
|
|||
|
simple, add a column on your forum table called last_reply. Then each time a post made update that field.
If you dont do it that way, then setup a user_id field (which should already be there) in the post table. Then by using the max(reply_id/auto_id) code as listed above you can determine your user.
__________________
-- Jason |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Retrieve info from tables joined? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|