这是我的代码,它也与数据库连接,但是看到图像,为什么它显示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
答案 0 :(得分:0)
您的查询执行了2个表的笛卡尔积。相反,您需要使用以下条件连接表:
select *
from playlist a,
tz_members b
where Byuser='$username'
and a.id = b.id
当然,您需要将a.id = b.id
更改为实际关系。