gpt4 book ai didi

php - 运行多个 SQL 查询以错误的顺序显示

转载 作者:行者123 更新时间:2023-11-30 00:39:01 25 4
gpt4 key购买 nike

我正在尝试运行这些 SQL 查询:

$sql2="SELECT * from client where parent_client_id = '".$result["customerid"]."' ";
$rs2=mysql_query($sql2,$pbx01_conn) or die(mysql_error());
while($result2=mysql_fetch_array($rs2)) {
$sql3="SELECT * from extension where client_id = '".$result2["id"]."' and type = 'term' ";
$rs3=mysql_query($sql3,$pbx01_conn) or die(mysql_error());
if(mysql_num_rows($rs3) > 0) {
$result3=mysql_fetch_array($rs3);
echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'sip:'.$result["customerid"].'*'.$result3["number"].'\'">
<td>'.$result2["name"].'</td>
<td>'.$result["customerid"].'*'.$result3["number"].'</td>
<td>Phone Terminal</td>
</tr>';
}
$sql3="SELECT * from extension where client_id = '".$result2["id"]."' and type = 'queue' ";
$rs3=mysql_query($sql3,$pbx01_conn) or die(mysql_error());
if(mysql_num_rows($rs3) > 0) {
$result3=mysql_fetch_array($rs3);
echo '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'sip:'.$result["customerid"].'*'.$result3["number"].'\'">
<td>'.$result2["name"].'</td>
<td>'.$result["customerid"].'*'.$result3["number"].'</td>
<td>Queue</td>
</tr>';
}

因此,如果在第一个 $sql3 上返回 4 行,则应该是:

Phone Terminal
Phone Terminal
Phone Terminal
Phone Terminal

在第二个 $sql3 上有 1 个返回,它应该是:

Queue

但它的显示就像

Phone Terminal
Phone Terminal
Phone Terminal
Queue
Phone Terminal

我做错了什么?

最佳答案

只需检查连接字符串时是否存在相同的问题,而不是回显。

<?php
$sql2 = "SELECT * from client where parent_client_id = '".$result["customerid"]."' ";
$rs2 = mysql_query($sql2,$pbx01_conn) or die(mysql_error());
$rows = '';
while ($result2 = mysql_fetch_array($rs2)) {
$sql3 = "SELECT * from extension where client_id = '".$result2["id"]."' and type = 'term' ";
$rs3 = mysql_query($sql3,$pbx01_conn) or die(mysql_error());
if (mysql_num_rows($rs3) > 0) {
$result3 = mysql_fetch_array($rs3);
$rows .= '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'sip:'.$result["customerid"].'*'.$result3["number"].'\'">
<td>'.$result2["name"].'</td>
<td>'.$result["customerid"].'*'.$result3["number"].'</td>
<td>Phone Terminal</td>
</tr>';
}
$sql3 = "SELECT * from extension where client_id = '".$result2["id"]."' and type = 'queue' ";
$rs3 = mysql_query($sql3,$pbx01_conn) or die(mysql_error());
if (mysql_num_rows($rs3) > 0) {
$result3 = mysql_fetch_array($rs3);
$rows .= '<tr class="notfirst" style="cursor:pointer;" onclick="document.location=\'sip:'.$result["customerid"].'*'.$result3["number"].'\'">
<td>'.$result2["name"].'</td>
<td>'.$result["customerid"].'*'.$result3["number"].'</td>
<td>Queue</td>
</tr>';
}
}
echo $rows;
?>

关于php - 运行多个 SQL 查询以错误的顺序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21934894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com