2011-04-09 40 views
1
$user_res_get = do_mysql_query("SELECT /* forums.php */ userid, subject, " . 
    " forumid FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__); 

和:PHP的MySQL的加入使用

$user_res_get = do_mysql_query("SELECT /* forums.php */ id, name, FROM " . 
    "forums WHERE id=$forumid") or sqlerr(__FILE__, __LINE__); 

forumd和id是相同

如何 「加盟」 呢?

我tryed創造這樣的事情:

$user_res_get = do_mysql_query("SELECT u.userid, u.subject, u.forumid, a.id, " . 
    "a.name FROM topics AS u JOIN forums as a ON u.forumid = a.id WHERE " . 
    "u.forumid=$topicid") or sqlerr(__FILE__, __LINE__); 

,但沒有運氣:/ 有什麼建議? 編輯: 螞蟻tryed與打印:

$user_row_get = mysql_fetch_assoc($user_res_get); 
$user_row_get['subject'] 
$user_row_get['name'] 

和其他...

+0

你不需要' AS'後面的表名就足夠了它的別名 – Dalen 2011-04-09 14:09:29

回答

2

相反的:

WHERE u.forumid=$topicid 

嘗試:

WHERE u.id=$topicid