title: Modal Button on each row displays modal which fetch details from database
body: <p>I have used table to fetch all records from two tables which is working good. I have added one button at end of each row which displays <strong>Modal</strong>. In this modal i want to display data based on each row ID.</p>
  
  <p>My code have one while loop which displays records in table,, in that while loop i have written one more sql statement which have a while loop and should run as per row ID, but it is taking only one rowId for both the rows, and displaying same modal to all rows</p>
  
  <p>Please help me out,, how to overcome these mistakes, and where im goin wrong.. Thank u very much for helping me n guiding the correct way
  <a href="https://i.stack.imgur.com/Dac1M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dac1M.png" alt="Below is the table, on clicking modal i want to display modal as per each row ID"></a></p>
  
  <p><a href="https://i.stack.imgur.com/AkCsD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AkCsD.png" alt="Below is modal which is fetching only one row ID"></a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  session_start();
  if(!isset($_SESSION)){
  header("Location: ../login.php");
  exit(); }
  
  include '../header.php';
  
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  
    &lt;!-- Content Wrapper. Contains page content --&gt;
    &lt;div class="content-wrapper"&gt;
      &lt;!-- Content Header (Page header) --&gt;
      &lt;section class="content-header"&gt;
        &lt;h1&gt;
          Processed Payment
          
        &lt;/h1&gt;
        &lt;ol class="breadcrumb"&gt;
          &lt;li&gt;&lt;a href="#"&gt;&lt;i class="fa fa-dashboard"&gt;&lt;/i&gt; Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Tables&lt;/a&gt;&lt;/li&gt;
          &lt;li class="active"&gt;Data tables&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/section&gt;
  
      &lt;!-- Main content --&gt;
      &lt;section class="content"&gt;
        &lt;div class="row"&gt;
          &lt;div class="col-xs-12"&gt;
            
            &lt;!-- /.box --&gt;
  
            &lt;div class="box"&gt;
              &lt;div class="box-header"&gt;
                &lt;h3 class="box-title"&gt; Processed Payment
       &lt;/h3&gt;
              &lt;/div&gt;
              &lt;!-- /.box-header --&gt;
     
     &lt;?php
  
  
     $email1 = $_SESSION['email'];
     $Vendor_id="SELECT Vendor_id FROM vendors where email = '$email1' ";
    $result=mysqli_query($conn,$Vendor_id);
    $row = mysqli_fetch_row($result);
    
  
  
     $sql = "SELECT cp.Customer_payment_id, cp.transaction_id,cp.type,co.Customer_order_id,co.shipping_method,co.tracking_id,co.service_name,co.expected_date_of_Delivery,co.payment_status  FROM customer_payment cp, customer_order co where cp.Customer_order_Customer_order_id=co.Customer_order_id and co.Vendors_Vendor_id=$row[0]";
     
     
     $query = mysqli_query($conn, $sql);
     if (!$query) {
      die ('SQL Error: ' . mysqli_error($conn));
     }
     
     ?&gt;
     
     
     
     
              &lt;div class="box-body"&gt;
      
                &lt;table id="example1" class="table table-bordered table-striped"&gt;
       &lt;form method="post"&gt;
                  &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;ID&lt;/th&gt;
       &lt;th&gt;Transaction ID&lt;/th&gt;
       &lt;th&gt;Payment Type&lt;/th&gt;
       &lt;th&gt;Status&lt;/th&gt;
       &lt;th&gt;Order_ID&lt;/th&gt;
       &lt;th&gt;Download&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                  
                  &lt;?php
  
        while ($row = mysqli_fetch_array($query))
        {
         
           $cpid=$row['Customer_payment_id'];
           $trd=$row['transaction_id'];
           $type=$row['type'];
           $pays=$row['payment_status'];
        ?&gt;
         &lt;tr&gt;
                  
           &lt;td&gt;&lt;?php echo $cpid;?&gt;&lt;/td&gt;
           &lt;td&gt;&lt;?php echo $trd;?&gt;&lt;/td&gt;
           &lt;td&gt;&lt;?php echo $type;?&gt;&lt;/td&gt;
           &lt;td&gt;&lt;?php echo $pays;?&gt;&lt;/td&gt;           
          &lt;td&gt;&lt;div class="box-body"&gt;
        &lt;button type="button" name="submit" value=&lt;?php echo $cpid;?&gt; class="btn btn-warning" data-toggle="modal" data-target="#modal-default1"&gt;
        Order ID&lt;/div&gt;
       
       
       
       
        &lt;div class="modal fade" id="modal-default1"&gt;
        &lt;div class="modal-dialog"&gt;
       &lt;div class="modal-content"&gt;
         &lt;div class="modal-header"&gt;
        &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
          &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
        &lt;h4 class="modal-title"&gt;Default Modal&lt;/h4&gt;
         &lt;/div&gt;
         &lt;div class="modal-body"&gt;
        &lt;div class="body table-responsive"&gt;
       
      &lt;table class="table"&gt;
      
      &lt;?php 
       
       $modal123 = "SELECT co.Customer_order_id, co.shipping_method,co.tracking_id,co.service_name,co.expected_date_of_Delivery  FROM customer_payment cp, customer_order co where cp.Customer_order_Customer_order_id=co.Customer_order_id and cp.Customer_payment_id=$cpid";
       
       $modalqry = mysqli_query($conn, $modal123);
       if (!$modalqry) {
        die ('SQL Error: ' . mysqli_error($conn));
       }
       
       while ($row = mysqli_fetch_array($modalqry))
        {
         $cid=$row['Customer_order_id'];
         $sm=$row['shipping_method'];
         $tid=$row['tracking_id'];
         $sn=$row['service_name'];
         $dod=$row['expected_date_of_Delivery'];           
       ?&gt;    
  
       &lt;thead&gt;
       &lt;tr&gt;
        &lt;th&gt;Order Track_ID&lt;/th&gt;
        &lt;th&gt;&lt;?php echo $cid;?&gt;&lt;/th&gt;
        
       &lt;/tr&gt;
       &lt;/thead&gt;
       &lt;tbody&gt;
         &lt;tr&gt;
        &lt;th scope="row"&gt;Shipping Method&lt;/th&gt;
        &lt;td&gt;&lt;?php echo $sm;?&gt;&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
        &lt;th scope="row"&gt;Tracking ID&lt;/th&gt;
        &lt;td&gt;&lt;?php echo $tid;?&gt;&lt;/td&gt;
        &lt;/tr&gt;
       &lt;tr&gt;
        &lt;th scope="row"&gt;Service Name&lt;/th&gt;
        &lt;td&gt;&lt;?php echo $sn;?&gt;&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
        &lt;th scope="row"&gt;Date of Delivery&lt;/th&gt;
        &lt;td&gt;&lt;?php echo $dod;?&gt;&lt;/td&gt;
       &lt;/tr&gt; 
        
        
        
       &lt;/tbody&gt;
        &lt;?php } ?&gt;
      &lt;/table&gt;
      &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
       &lt;button type="button" class="btn btn-default " data-dismiss="modal"&gt;Close&lt;/button&gt;
         
        &lt;/div&gt;
        
       &lt;/div&gt;
       
      &lt;!-- /.modal-content --&gt;
      &lt;/div&gt;
      
      &lt;!-- /.modal-dialog --&gt;
      &lt;/div&gt;
      
       &lt;/td&gt;
        
     &lt;td&gt;&lt;a href="../uploads/&lt;?php echo $cpid;?&gt;.pdf"&gt;&lt;div class="box-body"&gt;&lt;button type="button" class="btn btn-block btn-info "&gt;
             &lt;!--&lt;a href="#" class="w3-btn w3-black"&gt;&lt;/a&gt;--&gt;
             &lt;span&gt;Download&lt;/span&gt;
          &lt;/button&gt;
         &lt;/div&gt;&lt;/a&gt;&lt;/td&gt;
         
      
                  &lt;/tr&gt;
      &lt;?php       
      }
            
      ?&gt;
            
      
                  &lt;/tbody&gt;
                  &lt;tfoot&gt;
                  &lt;tr&gt;
                    &lt;th&gt;ID&lt;/th&gt;
       &lt;th&gt;Transaction ID&lt;/th&gt;
       &lt;th&gt;Payment Type&lt;/th&gt;
       &lt;th&gt;Status&lt;/th&gt;
       &lt;th&gt;Order_ID&lt;/th&gt;
       &lt;th&gt;Download&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;/tfoot&gt;
      &lt;/form&gt;
                &lt;/table&gt;
       
              &lt;/div&gt;
              &lt;!-- /.box-body --&gt;
            &lt;/div&gt;
            &lt;!-- /.box --&gt;
          &lt;/div&gt;
          &lt;!-- /.col --&gt;
        &lt;/div&gt;
        &lt;!-- /.row --&gt;
      &lt;/section&gt;
      &lt;!-- /.content --&gt;
    &lt;/div&gt;
    &lt;!-- /.content-wrapper --&gt;
   &lt;?php
  
  include '../footer.php';
  
  ?&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>