php
  • mysql
  • 2015-04-04 38 views 0 likes 
    0

    user_id可以在replies表中找到,但也可以在profiles表中找到。配置文件表具有real_name列。如何從另一個表中的while循環內的表中獲取數據?

    下面我得到所有 s的具體article_id。我的問題是,如何回覆保存在profiles表中的評論者的real_name

    我認爲這是表現。

    $replies = mysql_query("select * from replies where article_id = '$row[id]' order by timestamp desc"); 
    
    while($reply = mysql_fetch_assoc($replies)) { 
    
    I can echo the comments from the replies table, but how do I echo the real_name of each? 
    
    } 
    
    +0

    加入配置文件表?類似於'select p.real_name,r。* from reply as r join profiles as p on r.profileid = p.profileid where article_id ='$ row [id]'order by timestamp desc' might have to update the 'profileid'列名 – chris85 2015-04-04 15:53:12

    +0

    還可以查看[mysqli](http://php.net/manual/en/book.mysqli.php)或[PDO](http://php.net/manual/en /ref.pdo-mysql.php)作爲[mysql_](http://php.net/manual/en/function.mysql-connect.php)函數從PHP 5.5.0開始已棄用 – TheSk8rJesus 2015-04-04 16:24:47

    回答

    1

    嘗試:

    $replies = mysql_query("select * from replies,profiles where article_id = '$row[id]' AND replies.user_id=profiles.id order by timestamp desc"); 
    

    祝你好運!

    相關問題