» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2005, 07:39 AM
johny johny is offline
OSP Starters
 
Join Date: Dec 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
johny is on a distinguished road
Default Problem in Building my own Forum

I'm trying to build my own forum and I've got a problem with a query. I've got two tables and i need information out of both of them.

forum_table
1 forum_id (key)
2 forum_name
3 forum_created_by....

topic_table
1 topic_id (key)
2 topic_forum_id
3 topic_name
4 topic_created_by.....

When I want to list all the forums I also want to tell how many topics the forum has. Therefor I use the following query:


PHP Code:
$sql = "SELECT forum_table.*, COUNT(topic_table.topic_id) AS 'forum_topics' FROM forum_table, topic_table WHERE topic_table.topic_forum_id = forum_table.forum_id GROUP BY forum_table.forum_id ASC";

It works perfect.... though, there's one problem. If a forum has no topics, the query can't count the number of topics and so doesn't list the forum at all..

Please help me out? -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 12-07-2005, 07:40 AM
jami jami is offline
OSP Starters
 
Join Date: Dec 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
jami is on a distinguished road
Default Solution

Use variables or definitions in database queries instead of hard-coding table names.
PHP Code:
define('TBL_SESSIONS', 'tbl_sessions');
$result = mysql_query('SELECT * FROM ' . TBL_SESSIONS)


Use Prefixes
Prefix table and field names with short, meaningful identifiers. For example:

tbl_config
configId
cfgProfileId
cfgName
cfgValue

Use a consistent naming scheme
Whether your fields are called cfgProfileId or cfg_profile_id, stick to that convention with the rest of your fields. (Same for table names) -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
forum solution Jlima Web Hosting Industry 1 11-03-2006 02:48 AM
I joined DMOZ forum and had a bad experience. Benj Directories 1 08-29-2006 01:20 PM
link building with several forum sigs hookes Link Building 4 08-15-2006 02:34 AM
Revenue from link building. rangan Link Building 0 08-11-2006 11:31 AM
best approach for building new site ammie Web Hosting Industry 3 03-29-2006 02:13 PM


All times are GMT. The time now is 08:50 PM.