有什么办法只用一个while循环从两个表中获取数据?如何在一个while循环中从两个表中获取数据?
这里是代码:
<?php
$sql=mysql_query("select *from pm where send_to='$_GET[name]' limit $offset, $rowsperpage");
$sql2=mysql_query("select *from pm_reply where send_to='$_GET[name]' limit $offset, $rowsperpage");
$start_from = $offset + 1;
echo "<ol start='$start_from'>";
while($rows=mysql_fetch_assoc($sql))
{
echo"<li>From: <a href='profile.php?name=$rows[send_by]'>$rows[send_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows[subject]'>$rows[subject]</a></li>";
echo "<hr>";
echo "<br>";
}
while($rows2=mysql_fetch_assoc($sql2))
{
echo"<li>From: <a href='profile.php?name=$rows2[replied_by]'>$rows2[replied_by]</a><br><br><a style='text-decoration:none; font-size:14pt;' href='view_pm.php?name=$_GET[name]&pm=$rows2[subject]'>$rows2[subject]</a></li>";
echo "<hr>";
echo "<br>"
}
echo "</ol>";
?>
相信你能,一个可以完成比其他早期所以你必须检查过 – slash197
结合两种查询,通过加入或工会...这取决于在你的数据库结构上。 – user1844933
是的,尝试使用'JOIN',但两个表都需要具有像'id'一样的字段。 – rray