Home > OS >  I was trying to fetch all user Data in Transactions Table but it kept showing only One Row
I was trying to fetch all user Data in Transactions Table but it kept showing only One Row

Time:01-05

I needed to fetch all user data from the Database by email as my unique ID but it kept showing one Row

Here is my query function:

 public function fetchAirtimeTrans() {

        $email = $_SESSION['logged'];

        $query = $this->db->prepare("SELECT * FROM Transactions WHERE `email` = '$email' ORDER BY id ASC ");
        $query->execute();
        $query->setFetchMode(PDO::FETCH_ASSOC);
        $result = $query->fetchAll();

        return $result;

        
    }

and here's the result am getting: result

and my Database Transaction Table: transactions table

and my Index File with Table:

$datas = new Transactions();
$result = $datas->fetchAirtimeTrans();

if($result) {

    foreach( $result as $row) {
    }
    ?>
<?php
<tr>
<td> <?= $row[trans_id] </td>

</td>
</tr>

}

CodePudding user response:

I am assuming it's not a typo, it should be

$datas = new Transactions();
$result = $datas->fetchAirtimeTrans();

if($result) {

    foreach( $result as $row) {
    ?>
    <tr>
    <td> <?php echo $row['trans_id'];?> </td>
    </tr>
    <?php
    }
  • the trans_id is a string and needs to be quoted
  • the table row/data need to be within the loop, before the brace
  • and <?php and ?> were not correct
  • there was an extra </td>
  •  Tags:  
  • php
  • Related