我正在遍历一个带有循环的表,以将所有结果返回到一个漂亮的表中。直到子查询需要执行之前它都做得很好。子查询查看另一个表并使用起始循环中的 $office 值来查找信息,从那里它只是汇总整数值并将其分配给 $paid。
由于某种原因,两个循环在返回第一个结果并输出 $paid 后都会停止。甚至有可能完成我正在做的事情吗?我试图解决这个问题,似乎我可以对值进行硬编码并为每个结果集设置单独的变量,但这似乎需要做很多工作。我只想显示它从第一个循环返回的每个结果集的 $paid 整数。希望这一切都有意义。我非常感谢给出的任何建议。
$mysqli = new mysqli ( $db_hostname, $db_username, $db_password, $db_name );
$query = "select * from `drawer` where date(`date`) = '$mysql_date' order by `office`"; // select result set for selected date and order by office name
$result = $mysqli->query($query);
while ( $row = $result->fetch_assoc () ) {
echo "<tr class=table_border>\n"; //display results
echo "<td class=table_rows nowrap width=10%> ".$row['office']."</td>\n"; // return office name
$office = $row['office']; // grab the office from the first loop to use it in the second loop
echo "<td class=table_rows nowrap width=10%> ".$row['manager']."</td>\n"; // return manager name
echo "<td class=table_rows nowrap width=10%> ".$row['scash']."</td>\n"; // display integer value
echo "<td class=table_rows nowrap width=10%> ".$row['ecash']."</td>\n"; // display integer value
$newquery = "select * from `offer_det` where `office` = '$office' and date(date) = curdate()"; // subquery to display data from another table and insert for each row when the first loop starts
$resultquery = $mysqli->query($newquery);
while ($row=$resultquery->fetch_assoc()) {
$paid += $row['paid'];
}
echo "<td class=table_rows nowrap width=10%> ".$paid."</td>\n"; // both loops end here
echo "<td class=table_rows nowrap width=10%> ".$row['add']."</td>\n"; // should return integer value
echo "<td class=table_rows nowrap width=10%> ".$row['remove']."</td>\n"; // should return integer
echo "<td class=table_rows nowrap width=10%> ".$row['total']."</td>\n"; // should return integer
}