I’m running through a table with a loop to return all the results into a nice looking table. It does so fine up until the subquery needs to execute. The subquery looks at another table and uses the $office value from the starting loop to look up the information, from there it just totals up the integer value and assigns it to $paid.
For some reason both loops stop after it returns the first result and outputs $paid. Is it even possible to accomplish what I’m doing? I tried to wrap my head around this and it seems like I could hardcode the values and set individual variables for each result set, but that seems like a lot of work. I just want to display the $paid integer for each result set it returns from the first loop. Hopefully this all makes sense. I greatly appreciate any advice given.
$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
}
You are overwriting
$rowinto inner while loopChange
To