.PHP
<?php
$con = mysqli_connect("localhost", "*****", "*****", "******");
$query = ("SELECT * FROM profile");
$result = mysqli_query($con, $query);
while ($row = $result->fetch_assoc()) {
$query1 = ("SELECT vault_no FROM grp_tbl");
$result1 = mysqli_query($con, $query1);
while ($row1 = $result1->fetch_assoc()) {
if ($row1['vault_no'] !== $row['vault_no']) {
echo
'<div class = "chat-user-name"><span class="pull-right label label-primary"><input name="ppl" type="radio" value= "' . $row["via"] . '" "></span><div align="center"><input type="hidden" name="category" value="macro">
</div>
' . $row['via'] . ' </div>';
}
}
}
?>
答案 0 :(得分:5)
我认为最好的方法是在查询中使用LEFT JOIN,如下所示:
$query = "SELECT * FROM profile LEFT JOIN grp_tbl ON profile.vault_no <> grp_tbl.vault_no ORDER BY profile.YourOrderField";
我希望有人帮助
答案 1 :(得分:0)
在sql查询中使用join而不是使用嵌套查询和php循环,在这种情况下使用左连接:
select profile.*
from grp_tbl
left join profile on profile.vault_no<>grp_tbl.vault_no
order by profile.via
虽然目前还不清楚你在内循环中想要达到的目的是什么。
答案 2 :(得分:0)
像这样使用,它可能会起作用
<?php
$con = mysqli_connect("localhost", "*****", "*****", "******");
$query = ("SELECT profile.* from profile left join grp_tblon profile.vault_no!=grp_tbl.vault_no where profile.vault_no!=grp_tbl.vault_no");
$result = mysqli_query($con, $query);
while ($row = $result->fetch_assoc()) {
echo
'<div class = "chat-user-name"><span class="pull-right label label-primary"><input name="ppl" type="radio" value= "' . $row["via"] . '" "></span><div align="center"><input type="hidden" name="category" value="macro">
</div>
' . $row['via'] . ' </div>';
}
}
?>