Hi. Can you explain why I am getting this behavior with my loops?
Order 145 has 2 items. Order 146 has one item. Order 147 has 2 items, and order 149 has 3 items.
Here’s the results I’m getting:
current modal content for order 145: Profit: 4.97 test test test test test
current modal content for order 146: Profit: 14.57 test test test test test
current modal content for order 145: Profit: 2.25 test test test test test
current modal content for order 147: Profit: 19.97 test test test test test
current modal content for order 147: Profit: 19.97 test test test test test Profit: 24.95 test test test test test
current modal content for order 149: Profit: 29.55 test test test test test
current modal content for order 149: Profit: 29.55 test test test test test Profit: -5.50 test test test test test
current modal content for order 149: Profit: 29.55 test test test test test Profit: -5.50 test test test test test Profit: 29.94 test test test test test
And here are the results I am expecting:
current modal content for order 145: Profit: 4.97 test test test test test Profit: 2.25 test test test test test
current modal content for order 146: Profit: 14.57 test test test test test
current modal content for order 147: Profit: 19.97 test test test test test Profit: 24.95 test test test test test
current modal content for order 149: Profit: 29.55 test test test test test Profit: -5.50 test test test test test Profit: 29.94 test test test test test
Here’s my code, and I’ve tried multiple other varieties of swapping around the wording and loops but nothing gives me the result I expect. The code on the page is very long so I will just paste the relevant part:
/*Inside a While Loop fetching results from database:*/
if ($current_modal != $row['sale_id']) {
$modal_data_content = '';
}
$modal_data_content .= '
<tr>
<td>Profit: '.$profit.'</td>
<td>test</td>
<td>test</td>
<td>test</td>
<td>test</td>
<td>test</td>
</tr>';
$current_modal = $row['sale_id'];
echo 'current modal content for order '.$sale_id.': '.$modal_data_content. '<br>';