I really need help for this one, im new on this php oop. my problem here i can only display a data on a single row of my table. here is my function class
<?php
include('connection.php');
class guestDetails{
public function guest($id){
$query = mysql_query("SELECT * FROM tb_member WHERE memberID = '{$id}' ");
$row = mysql_fetch_array($query);
return $row;
}
}
?>
And here is where i have foreach loop:
<table class="table table-bordered" id="table_id">
<thead>
<tr>
<th>Booking No.</th>
<th>Date</th>
<th>RoomType</th>
<th>Guest</th>
<th>Status</th>
<th>Payment</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$lists = new crudBooking;
$list = $lists->viewBooking();
$rows = new guestDetails;
foreach($list as $key => $value){
$id = $value['reserveID'];
$from = new DateTime( $value['arrival'] );
$to = new DateTime( $value['departure'] );
?>
<tr>
<td><?php echo $value['reserveID']; ?></td>
<td><?php echo $from->format( 'F d, Y' ) . " - " . $to->format( 'F d, Y' ); ?></td>
<td><?php echo $value['category_id']; ?></td>
<td>
<?php
$row = $rows->guest($value['reserveID']);
echo $row['firstname'] . " " . $row['lastname'] . "<br /><a href='#'>" . $row['email'] . "</a>";
?>
</td>
<td><?php echo $value['status']; ?></td>
<td>to be edited</td>
<td style="text-align: center;">
<!-- Split button -->
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm">Action</button>
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-asterisk"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="<?php echo $value['reserveID']; ?>" data-toggle="modal" data-target="#editProduct<?php echo $value['reserveID']; ?>">Check-in</a></li>
<li><a href="<?php echo $value['reserveID']; ?>" data-toggle="modal" data-target="#deleteProduct<?php echo $value['reserveID']; ?>">Check-out</a></li>
<li><a href="<?php echo $value['reserveID']; ?>" data-toggle="modal" data-target="#deleteProduct<?php echo $value['reserveID']; ?>">Cancel</a></li>
<li><a href="<?php echo $value['reserveID']; ?>" data-toggle="modal" data-target="#deleteProduct<?php echo $value['reserveID']; ?>">More Details</a></li>
</ul>
</div>
</td>
<?php include('includes/modals.php'); ?>
</tr>
<?php } ?>
</tbody>
</table>
The problem here is it only return on the first row of my table.
This is the code where i call the return value of guest() class:
<td>
<?php
$row = $rows->guest($value['reserveID']);
echo $row['firstname'] . " " . $row['lastname'] . "<br /><a href='#'>" . $row['email'] . "</a>";
?>
</td>

whileloop on the query (likewhile ($row=mysql_fetch_array){ ...}; otherwise you will just get the first row returned. Also, I recommend using a prepared statement, rather than writingiddirectly into your query.