2016-02-26 64 views
0

作爲用戶,我想在我登錄時查看我的配置文件。我想查看的數據來自使用user_id的另一個表。如何使用user_id從另一個表中獲取數據

我試過下面的代碼,但是我得到了表中的所有數據。我試過使用session_id,但它不起作用。

這裏是我的代碼:

<div> 
    <table style="border: 2px solid black;"> 
     <tr> 
      <th>Users Id</th> 
      <th>Language from</th> 
      <th>Language to</th> 
      <th>Category name</th> 
      <th>Message</th> 
      <th>File Name</th> 
      <th>Number of words of file</th> 
      <th>Count of words paste</th> 
      <th>Total</th> 
     </tr> 
     <?php 
     //$user_id = $_SESSION['user_id']; 
     $res = mysql_query("SELECT * from checkout JOIN users WHERE users.user_id = checkout.user_id"); 
     while($row = mysql_fetch_array($res)) 
     { 
      ?> 
      <tr> 
       <td><?php echo $row['user_id']; ?></td> 
       <td><?php echo $row['language_from']; ?></td> 
       <td><?php echo $row['language_to']; ?></td> 
       <td><?php echo $row['category_name']; ?></td> 
       <td><?php echo $row['message']; ?></td> 
       <td><?php echo $row['file']; ?></td> 
       <td><?php echo $row['file_count']; ?></td> 
       <td><?php echo $row['word_count']; ?></td> 
       <td><?php echo $row['total']; ?></td> 
      </tr> 
      <?php 
     } 
     ?> 
    </table> 
</div> 

請儘量幫我,你們...

+0

使用'WHERE'子句使用用戶ID – Ghost

+0

'WHERE users.user_id = checkout.user_id'我試過了,但它有相同的輸出 – angel1108

+0

使用這個WHERE users.user_id = checkout.user_id AND users.user_id = $ user_id''$ user_id = $ _SESSION ['user_id']' –

回答

1

我不明白,如果你已經有了USER_ID只是做

SELECT * FROM users WHERE id = <your user_id> 

或者修復您的第一個請求

SELECT u.* 
FROM users AS u 
INNER JOIN checkout AS c 
ON u.id = c.user_id 
WHERE u.id = <id> 
+0

我已經嘗試過這兩個,但它不工作先生... – angel1108

+1

然後解釋我們你有什麼和你想要檢索什麼,問題還不清楚。 – Sakuto

+0

我已經更新了我的問題,上面先生。 ^^ – angel1108

相關問題