» 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 08-02-2006, 05:17 PM
distinct distinct is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
distinct is on a distinguished road
Red face include table title

Hello

I am modifying someone else's code, and having the following problem.

Code:

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.forum_assoc FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

f.last_post_id refers to the id of an entry in the table posts. The entry in the table post contains the topic id, which contains the topic title.

Does anyone have any idea as to how I can modify this query to include the topic title? -- 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 08-02-2006, 05:22 PM
techguru techguru is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
techguru is on a distinguished road
Default

Couldn't understood you fully, but i think this is what you want

select c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, ( select title from posts where topic_id = f.last_post_id ) as topic_title , f.last_poster, f.forum_assoc from '.$db->prefix.'categories AS c inner join '.$db->prefix.'forums AS f on c.id=f.cat_id left join '.$db->prefix.'forum_perms AS fp on (fp.forum_id=f.id and fp.group_id='.$pun_user['g_id'].') where fp.read_forum is null or fp.read_forum=1 order by c.disp_position, c.id, f.disp_position

Bye -- 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
  #3  
Old 08-02-2006, 05:26 PM
owais owais is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
owais is on a distinguished road
Default

posting the same code as techgure but in more readable form, see for yourself


select c.id AS cid
, c.cat_name
, f.id AS fid
, f.forum_name
, f.forum_desc
, f.redirect_url
, f.moderators
, f.num_topics
, f.num_posts
, f.last_post
, f.last_post_id
, ( select title
from posts
where topic_id
= f.last_post_id ) as topic_title
, f.last_poster
, f.forum_assoc
from '.$db->prefix.'categories AS c
inner
join '.$db->prefix.'forums AS f
on c.id=f.cat_id
left
join '.$db->prefix.'forum_perms AS fp
on (fp.forum_id=f.id
and fp.group_id='.$pun_user['g_id'].')
where fp.read_forum is null
or fp.read_forum=1
order
by c.disp_position
-- 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
unable to add posts to a phpbb table after moving servers. tanny MySQL Forums 3 02-13-2007 03:44 PM
adding value to the table. Eshur MySQL Forums 1 11-29-2006 06:36 AM
temp table generation? Bshishe MySQL Forums 1 11-07-2006 04:28 AM
designing table relations? Jett MySQL Forums 1 08-17-2006 10:23 AM
error= #1036 - Table 'table' is read only futuristic PHP Programming and Tips 1 08-12-2006 10:21 AM


All times are GMT. The time now is 09:52 AM.