因此,我对MySQL返回2行有问题,但是在变量中仅显示1行。
不确定为什么不同时返回
$sql->bind_result($c_id, $c_location, $c_type) or die($mysqli_load->error);
while($row = $sql->fetch()){
$mysqli_load2 = new mysqli(HOST, USER, PASS, DB);
$query = "SELECT `badge` FROM `responders` WHERE `cid` = ?";
$sql2 = $mysqli_load2->prepare($query) or die($mysqli_load2->error);
$sql2->bind_param('i', $c_id);
$sql2->execute() or die($mysqli_load2->error);
$sql2->store_result();
$rows = $sql2->num_rows;
$sql2->bind_result($units);
$sql2->fetch();
$sql2->close();
$mysqli_load2->close();
echo '
<tr>
<td align="justify"><a href="viewcall.php?cid=' . $c_id .'"><u><abbr title="View Call">'.$c_id.'</abbr></u></td>
<td align="justify">' . $c_location .'</td>
<td align="justify">' . $c_type .'</td>
<td align="justify">Rows: ' . $rows . ' ' . $units . '</td></tr>';
}
最佳答案
您需要使用fetch()方法进行循环:
while ($sql2->fetch()) {
echo $units;
}
$sql2->close();