基本上我有2张桌子
- 话题
- 用户
我正在尝试使用左连接,以便我可以将“主题”中的“posted_by”与“用户”中的“user_id”链接起来,这样我就可以输出 users.username 以供显示,以及 users.profile(头像图片)。
这是我当前的代码,它给了我布尔错误。
<?php
include 'core/init.php';
include 'includes/overall/header.php';
$sql = " SELECT *, users.id, users.username, users.profile
FROM `topics`
LEFT JOIN
users ON topics.posted_by = " . mysql_real_escape_string($_GET['topic_id']) . " users.user_id ORDER BY `posted` DESC";
$result = mysql_query($sql);
// Start looping table row
while($rows = mysql_fetch_array($result)){
?>
<table>
<tr>
<td rowspan="4"> Avatar code to go here<br>
<? echo $rows['username']; ?></td>
<td><? echo $rows['category']; ?> > <? echo $rows['sub_category']; ?> </td>
</tr>
<tr>
<td><? echo $rows['posted']; ?></td>
</tr>
<tr>
<td><? echo $rows['topic_data']; ?></td>
</tr>
<tr>
<td><a href="view_topic.php?id=<? echo $rows['topic_id']; ?>">Reply</a> (<? echo $rows['reply']; ?>) Replies</td>
</tr>
</table>
<?php
// Exit looping and close connection
}
mysql_close();
?>