Below $pdo is the sum of price output to html output which is success. How can i list out each entry for this total price?
I know the sql should use "SELECT t.table_type, price, start_time, end_time FROM table_booking b JOIN tables t USING (table_id) WHERE date(end_time) = curdate()".
PHP code
ajax code
html output
I know the sql should use "SELECT t.table_type, price, start_time, end_time FROM table_booking b JOIN tables t USING (table_id) WHERE date(end_time) = curdate()".
PHP code
Code:
elseif ($_GET['ajax'] == 'getReceipts') {
$res = $pdo->query("SELECT t.table_type
, sum(price) as total
FROM table_booking b
JOIN
tables t USING (table_id)
WHERE date(end_time) = curdate()
GROUP BY table_type
");
$tots = [ '1'=>0, '2'=>0 ];
foreach ($res as $r) {
$tots[$r['table_type']] = $r['total'];
}
$resp['snTot'] = number_format($tots['1'], 2);
exit(json_encode($resp));
}
ajax code
Code:
$("#show-receipts").click( function() {
$.get(
"",
{"ajax":"getReceipts"},
function(resp) {
$.each(resp, function(k, v) {
$("#"+k).html(v)
})
},
"JSON"
)
$("#modalRecpts").show()
})
html output
Code:
<div class='w3-modal' id='modalRecpts'>
<div class='w3-card-4 w3-modal-content w3-sand'>
<div class="w3-container w3-purple">
<h3>Today's Receipts</h3>
<span onclick="document.getElementById('modalRecpts').style.display='none'"
class="w3-button w3-display-topright">×</span>
</div>
<div class='w3-container w3-padding'>
<table class='w3-table'>
<tr><th>Snooker</th><td id='snTot' class='w3-right-align'>$0.00</td></tr>
</table>
</div>
</div>
</div>