PHP Mysql无法正常回显内连接

时间:2017-01-12 10:04:45

标签: php html mysql

为什么这段代码没有回应任何东西 我真的希望你能帮助我:) 它是我的网站。

表格结构:http://imgur.com/a/M6Y9t

<?php
$q = mysql_query("SELECT user_1_id AS user1, users2.username AS user2, firewind_trades.id, firewind_trades.timestamp
                FROM `firewind_trades`
                INNER JOIN `users` users1 on firewind_trades.1id = users1.id
                INNER JOIN `users` users2 on firewind_trades.2id = users2.id
                ORDER BY id DESC;");
while ($m = mysql_fetch_array($q)) { 
    echo '
    <tr>
        <td >'.$m['id'].'</td>
        <td >'.$m['user1'].'</td>
        <td >'.$m['user2'].'</td>
        <td >'.$m['timestamp'].'</td>
        <td ><a href="index.php?url=hk&tradelogs&id='.$m['id'].'">Vis byttehandel</a></td>
    </tr>
    ';
}
?>

2 个答案:

答案 0 :(得分:0)

如果你在mySQL客户端吃午餐,你有结果吗?因为我没有在firewind_trades表中看到这些字段firewind_trades.1idfirewind_trades.2id

也许你可以试试:

INNER JOIN `users` users1 on firewind_trades.user_1_id = users1.id
INNER JOIN `users` users2 on firewind_trades.user_2_id = users2.id

答案 1 :(得分:0)

我认为你在选择&amp; amp;加入字段。 试试这个:

 <?php
$q = mysql_query("SELECT users1.username AS user1, users2.username AS user2, firewind_trades.id, firewind_trades.timestamp
            FROM `firewind_trades`
            INNER JOIN `users` users1 on firewind_trades.user_1_id = users1.id
            INNER JOIN `users` users2 on firewind_trades.user_2_id = users2.id
            ORDER BY id DESC;");
while ($m = mysql_fetch_array($q)) {
echo '
<tr>
    <td >'.$m['id'].'</td>
    <td >'.$m['user1'].'</td>
    <td >'.$m['user2'].'</td>
    <td >'.$m['timestamp'].'</td>
    <td ><a href="index.php?url=hk&tradelogs&id='.$m['id'].'">Vis byttehandel</a></td>
</tr>
';
}
?>