My code looks something like this, I know it's a big chunk.
Code: Select all
$balance_before_transaction_query = mysqli_query($connect,
"SELECT transaction_balance FROM transactions WHERE user_id = '$id_of_logged_in_user' ORDER BY id DESC LIMIT 1;");
while ($row1 = mysqli_fetch_array($balance_before_transaction_query)) {
$current_balance = $row1['transaction_balance'];
}
?>
<h2> Hey <?php echo $access_control['username']; ?>, you currently have <b> <?php echo $current_balance; ?> </b> PLN</h2>
<h2>Spendings Table</h2>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr class="tablehead">
<th>#</th>
<th>Amount</th>
<th>Date</th>
<th>Category</th>
<th>Notes</th>
<th>Balance</th>
<th>Delete Confirmation</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$result = mysqli_query($connect, "SELECT * FROM transactions
WHERE user_id = '$id_of_logged_in_user' ORDER BY `transaction_date` DESC;");
while ($row = mysqli_fetch_array($result)) {
?>
<form method="POST" action="balance.php">
<tr class="tablebody">
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['transaction_amount']; ?></td>
<td><?php echo $row['transaction_date']; ?></td>
<td><?php echo $row['transaction_category'] ?></td>
<td><?php echo $row['transaction_details']; ?></td>
<td><?php echo $row['transaction_balance']; ?></td>
<td><p>Type "Confirm" to Continue</p>
<input type="text" name="inputConfirmation" required></td>
<td><button type="submit" name="transaction_id" class="btn btn-danger">Delete</button></td>
</tr>
</form>
<?php
}
?>
<?php
$transaction_id = $_POST['transaction_id'];
$resultDelete = mysqli_query($connect, "DELETE FROM transactions where $transaction_id = " . $row['id'] . ";");
?>
</tbody>
</table>