2

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>

Here is the table enter image description here

2
  • You should use a while loop on the query (like while ($row=mysql_fetch_array){ ...}; otherwise you will just get the first row returned. Also, I recommend using a prepared statement, rather than writing id directly into your query. Commented Jul 25, 2015 at 4:39
  • i tried this but i dont know if its correct but when i tried it only showed the data on first row public function guest($id){ $query = mysql_query("SELECT * FROM tb_member WHERE memberID = '{$id}' "); while($rows = mysql_fetch_array($query)){ $row[] = $rows; } return $row; } Commented Jul 25, 2015 at 4:59

1 Answer 1

2

are you sure tb_member.memberID have all reserveID, do something like

 $row = $rows->guest($value['reserveID']);
 if(!$row){
  echo "NO this member,reserveID:".$value['reserveID'];
  }else{
     echo $row['firstname'] . " " . $row['lastname'] . "<br /><a href='#'>" . $row['email'] . "</a>";
 }

if reserveID is not memberID

 $row = $rows->guest($value['YOUR MENBER ID COLUME NAME']);
Sign up to request clarification or add additional context in comments.

3 Comments

no im querying my tb_reserved that has a memberID i just dont know if i need to show that too sorry,.. i just want to show the details about that memberID from tb_reserved
then uses $rows->guest($value['memberID']);
oh my god it works :D tnx a lot what a shame on me huhu for posting this one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.