A Digital Age Deserves A Digital Leader

Another php code question

Another php code question

Postby kanaloa » Thu Sep 14, 2006 7:08 pm

php question for ya.

I have this line in phpbb:
$topic_sql = "SELECT t.topic_id, t.topic_title, t.topic_replies, t.topic_views, u.username, u.user_id FROM phpbb_topics t, phpbb_users u WHERE t.forum_id = $forum_id AND t.topic_poster = u.user_id ORDER BY topic_last_post_id DESC LIMIT $limit";

And all I want to do is include this variable: f.forum_name

Problem is that is comes out of the phpbb forums table "f". How can I make the above line pull that variable so I can get the forum's name?

Thanks for any help you can provide on that snippet.
"Greatness is not a function of circumstance. Greatness, it turns out, is largely a matter of conscious choice, and discipline." - Jim Collins
President
User avatar
Posts: 11795
Joined: Sun Mar 10, 2002 1:18 am
Location: HI & SC
Real Name: John Derrick

Postby jbullard » Thu Sep 14, 2006 10:08 pm

What you have to do is setup an alias name for that table in your SQL statement. I am guessing "f" stands for forum so it would be something like this

$topic_sql = "SELECT t.topic_id, t.topic_title, t.topic_replies, t.topic_views, u.username, u.user_id, f.forum_name FROM phpbb_topics t, phpbb_users u, phpbb_forums f WHERE t.forum_id = $forum_id AND t.topic_poster = u.user_id ORDER BY topic_last_post_id DESC LIMIT $limit";

You also need to setup a WHERE clause which would be, I believe in the topics table it is still labeled as forum_id. So you would also need to add to the WHERE clause

$topic_sql = "SELECT t.topic_id, t.topic_title, t.topic_replies, t.topic_views, u.username, u.user_id, f.forum_name FROM phpbb_topics t, phpbb_users u, phpbb_forums f WHERE t.forum_id = $forum_id AND t.topic_poster = u.user_id AND f.forum_id = t.forum_id ORDER BY topic_last_post_id DESC LIMIT $limit";

HTH
VP - Software
User avatar
Posts: 3653
Joined: Sun Jun 06, 2004 10:17 pm
Location: Utah
Real Name: Jason Bullard

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 5 guests