In my SQL Database, I have a table "TRANSFER" and columns with "amount_cr" and "amount_db." In my PHP Code, I have a PHP file that sends a report in the figure to $amount_cr while another file sends to $amount_db. I need a situation where a table shows the two columns using an IF Statement. That is when $amount_cr is input, let $amount_db remain blank, and vice versa.
<tr>
<th scope="col">AMOUNT CR</th>
<th scope="col">AMOUNT DB</th>
</tr>
<?php
$cs_id = $_SESSION['cs_id'];
$his = $reg_user->runQuery("SELECT * FROM transfer WHERE cs_id = '$cs_id' ORDER BY id DESC LIMIT 3");
$his->execute(array(":cs_uname" => $_SESSION['cs_uname']));
while($rows = $his->fetch(PDO::FETCH_ASSOC))
?>
// I tried the following as a newbie
<tr>
<td style="color:green;" scope="row">+ $ <?php echo $rows['amount_cr']; ?></td>
<td style="color:red;" scope="row">- $<?php echo $rows['amount_db']; ?></td>
</tr>
This is what I get as the output enter image description here
I wish to have the output this way enter image description here
Amount (Credit) | Amount (Debit)
When the incoming input is for amount_cr, it appears on the amount_cr column while amount_db remain blank, vice versa. Like what I have on the Image
ifstatements. These are program flow control structures. You can use anifstatement to conditionally display the value.'$cs_id'? It should be:cs_unameor something like that