<a data-toggle="modal" data-id="<?php $row_dtodaytransferRecordset1['id'];?>" href="#mymodal" class="open-dialog btn btn-primary btn-xs"  data-target="#myModal" >view passengers</a>





<!-- pop up starts here for view passengers -->
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">


        <div class="modal-content">


      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>

  <?php   

$id = $row_dtodaytransferRecordset1['id'];
mysql_select_db($database_cn, $cn);

$query_paxRecordset1 =  "SELECT passengers.id, transfers.voucher_ref, passengers.phone, passengers.passenger_name FROM passengers INNER JOIN transfers ON passengers.voucher_ref = transfers.voucher_ref WHERE transfers.id = $id"; 
$paxRecordset1 = mysql_query($query_paxRecordset1, $cn) or die(mysql_error());
$row_paxRecordset1 = mysql_fetch_assoc($paxRecordset1);
$totalRows_paxRecordset1 = mysql_num_rows($paxRecordset1);

?>

 <table class="table table-hover table-bordered" >
    <tr style=" background-color:#00AAAD; color:#FFF; ">
      <td>Passenger Name </td>
      <td>Mobile No</td>  
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_paxRecordset1['passenger_name']; ?></td>
        <td><?php echo $row_paxRecordset1['phone']; ?></td>
       </tr>
       <?php  

        } while ($row_paxRecordset1 = mysql_fetch_assoc($paxRecordset1)); ?>
  </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

 <!-- end of pop up --> 
Member Avatar for diafol

Coupla points:

1) Don't use mysql_* functions they're DEPRECATED. Use PDO or mysqli.
2) Don't mix up your markup and php - keep them as separaate as possible. E.g. place all your php at the beginning of the file (or better still in an include file).

If it makes no difference that the data is loaded on page load, then use vanilla php. However, if you have a few different links with different ids that can call the model, so it can be populated with different data, then use ajax (js + php).

Example:

<?php
$id = $row_dtodaytransferRecordset1['id'];
$db = new PDO(...details...);
$q = "SELECT passengers.id, transfers.voucher_ref, passengers.phone, passengers.passenger_name FROM passengers
        INNER JOIN transfers ON passengers.voucher_ref = transfers.voucher_ref WHERE transfers.id = ?";
$stmt = $db->prepare($q);
$stmt->execute(array($id));
$passengers = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rows = count($passengers);
?>

<a data-toggle="modal" data-id="<?=$id ?>" href="#mymodal" class="open-dialog btn btn-primary btn-xs"  data-target="#myModal" >view passengers</a>
<!-- pop up starts here for view passengers -->
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
        <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<table class="table table-hover table-bordered" >
    <tr style=" background-color:#00AAAD; color:#FFF; ">
        <td>Passenger Name </td>
        <td>Mobile No</td>
    </tr>
    <?php foreach($passengers as $p){ ?>
        <tr>
            <td><?=$p['passenger_name'] ?></td>
            <td><?=p['phone'] ?></td>
        </tr>
    <?php } ?>
</table>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- end of pop up -->

BTW - you need to sort out the indentation on your markup. Confusing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.