General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 17th, 2003, 02:55 PM
wareseeker wareseeker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 71 wareseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 7 sec
Reputation Power: 6
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:
 CREATE TABLE forum (
  
forumid int(25NOT NULL auto_increment,
  
title varchar(255NOT NULL default '',
  
description varchar(255NOT NULL default '',
  
PRIMARY KEY  (id)
TYPE=MyISAM;

CREATE TABLE thread (
  
threadid int(25NOT NULL auto_increment,
  
forumid int(25NOT NULL default '0',
  
username
  PRIMARY KEY  
(id)
TYPE=MyISAM;

CREATE TABLE reply (
  
replyid int(25NOT NULL auto_increment,
  
threadid int(25NOT NULL default '0',
  
username
  PRIMARY KEY  
(id)
TYPE=MyISAM

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!

Reply With Quote
  #2  
Old November 17th, 2003, 04:46 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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))
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old November 17th, 2003, 10:18 PM
wareseeker wareseeker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 71 wareseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 7 sec
Reputation Power: 6
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:
 CREATE TABLE forum (
  
forumid int(25NOT NULL auto_increment,
  
title varchar(255NOT NULL default '',
  
description varchar(255NOT NULL default '',
  
PRIMARY KEY  (id)
TYPE=MyISAM;

CREATE TABLE thread (
  
threadid int(25NOT NULL auto_increment,
  
forumid int(25NOT NULL default '0',
  
username varchar(15NOT NULL default '',
  
topic varchar(255NOT NULL default '',
  
content text,
  
views int(25NOT NULL default '0',
  
postdate datetime NOT NULL default '0000-00-00 00:00:00',
  
editdate datetime NOT NULL default '0000-00-00 00:00:00',
  
PRIMARY KEY  (id)
TYPE=MyISAM;

CREATE TABLE post (
  
replyid int(25NOT NULL auto_increment,
  
threadid int(25NOT NULL default '0',
  
username varchar(15NOT NULL default '',
  
subject varchar(255NOT NULL default '',
  
content text,
  
postdate datetime NOT NULL default '0000-00-00 00:00:00',
  
editdate datetime NOT NULL default '0000-00-00 00:00:00',
  
PRIMARY KEY  (id)
TYPE=MyISAM

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.

Reply With Quote
  #4  
Old November 17th, 2003, 10:30 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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.

Reply With Quote
  #5  
Old November 17th, 2003, 11:04 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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.

Reply With Quote
  #6  
Old November 17th, 2003, 11:18 PM
wareseeker wareseeker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 71 wareseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 7 sec
Reputation Power: 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!

Reply With Quote
  #7  
Old November 20th, 2003, 07:20 PM
numbernine numbernine is offline
Up To His Eyes In Ads
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Chicago
Posts: 160 numbernine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 25 sec
Reputation Power: 6
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..

Reply With Quote
  #8  
Old November 21st, 2003, 09:38 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Retrieve info from tables joined?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway