开发者

php mysql join usage

$user_res_get = do_mysql_query("SELECT /* forums.php */ userid, 开发者_开发百科subject, " .
    " forumid FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);

and:

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

forumd and id are identical

How to "JOIN" them ?

I tryed create something like this:

$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__);

But no luck :/ Any suggestions ? EDIT: Ant tryed to print with:

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

and others...


Instead of:

WHERE u.forumid=$topicid

try:

WHERE u.id=$topicid
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜