这是我的代码,它也与数据库连接,但是看到图像,为什么它显示2倍相同的ID和其他行?

这是显示的屏幕截图:/

<?php
$username = $_SESSION['usr'];
        // get results from database
        $result = mysql_query("SELECT * FROM playlist, tz_members WHERE Byuser='$username'")
                or die(mysql_error());


        echo "<table id='table_example'><thead>";
        echo "<tr><th width='1%'>ID</th><th width='10%'>Kengtar(<i><span style='color: blue'>i</span></i>/<i>ja</i>)</th><th width='5%'>Kenga</th><th width='7%'>Albumi</th><th width='2%'>Data</th></tr>";
        echo "</thead><tbody>";

        while($row = mysql_fetch_array( $result )) {

        echo "<tr>";
        echo '<th>#' . $row['ID'] . '</th>';
        echo '<td>' . $row['Kengtar'] . '</td>';
        echo '<td>' . $row['Kenga'] . '</td>';
        echo '<td>' . $row['Albumi'] . '</td>';
        echo '<td>' . $row['Data'] . '</td>';
        echo "</tr>";
    }
        echo "</table>";
?>

谢谢你,如果有人想帮助我,我是php codind的新手:S

最佳答案

您的查询做了2个表的笛卡尔积。相反,您需要使用以下条件连接表:

select *
from playlist a,
     tz_members b
where Byuser='$username'
      and a.id = b.id

当然,您需要将a.id = b.id更改为实际关系。

10-06 07:25
查看更多