bootstrap模式和使用php的mysql查询

xmakbtuz  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(293)

我试图让mysql数据显示在一个引导模式上,出于某种原因,它只是拉第一个链接的id被点击,而不是链接上指定的行的id被点击来显示所说的模式(希望这是有意义的)。
要单击的链接:

<a data-toggle="modal" data-target="#leadModal" href="?id=<?php echo $id; ?>"><?php echo $f; echo '&nbsp;'; echo $l; ?></a>

下面是围绕链接的代码:

<div class="table-responsive">
        <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
          <thead>
            <tr>
              <th>Name</th>
              <th>Email Address</th>
              <th>Primary Phone</th>
              <th>Date Created</th>
              <th>Arrival Date</th>
              <th>Departure Date</th>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <th>Name</th>
              <th>E-Mail Address</th>
              <th>Primary Phone</th>
              <th>Date Created</th>
              <th>Arrival Date</th>
              <th>Departure Date</th>
            </tr>
          </tfoot>
          <tbody>
          <?php
$agent = $userRow['userName'];

$query = "SELECT * FROM leads WHERE status='Follow-Up' && agent='$agent'";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
$f = $line['first'];
$l = $line['last'];
$e = $line['email'];
$p1 = $line['PrimePhone1'];
$p2 = $line['PrimePhone2'];
$p3 = $line['PrimePhone3'];
$a = $line['arrival'];
$d = $line['departure'];
$ag = $line['agent'];
$id = $line['id'];
$dc = $line['datecreated'];
$es = $line['emailsent'];
?>
            <tr>
              <td><a data-toggle="modal" data-target="#leadModal" href="?id=<?php echo $id; ?>"><?php echo $f; echo '&nbsp;'; echo $l; ?></a></td>
              <td><?php echo $e; ?></td>
              <td><?php echo $p1; echo '-'; echo $p2; echo'-'; echo $p3; ?></td>
              <td><?php echo $dc; ?></td>
              <td><?php echo $a; ?></td>
              <td><?php echo $d; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </div>
    </div>

下面是代码在模式中显示数据的内容:

<!-- Lead Modal-->
    <div class="modal fade" id="leadModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header"><?php
          $id = $_GET["id"];
           $query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
            <h5 class="modal-title" id="exampleModalLabel"><?php echo $line['first']; ?>&nbsp;<?php echo $line['last']; ?>'s Existing Lead</h5><?php } ?>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body"><?php

$id = $_GET["id"];
$query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 

?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr align="center">
    <td>
<table width="750" border="2" align="center" cellpadding="1" cellspacing="0" class="table">

  <tr>    
        <td>Original Agent:</td>
    <td><?php echo $line['agent']; ?></td>
  </tr>
 <?php if ($line['upagent'] == ''){  } else { ?>   <tr>    
        <td>Last Updated By:</td>
    <td><?php echo $line['upagent']; ?></td>
  </tr><?php } ?>
  <tr>
    <td width="186">First Name:</td>
    <td width="552">
      <?php echo $line['first']; ?></td>
  </tr>
<?php if ($line['last'] == ''){  } else { ?>  <tr>
    <td>Last Name:</td>
    <td><?php echo $line['last']; ?></td>
  </tr><?php } ?>
  <?php if ($line['email'] == ''){  } else { ?><tr>
    <td>E-Mail Address:</td>
    <td><?php echo $line['email']; ?></td>
  </tr><?php } ?>
  <tr>
    <td>Primary Phone:</td>
    <td><?php echo $line['PrimePhone1']; echo '-'; echo $line['PrimePhone2']; echo '-'; echo $line['PrimePhone3']; ?></td>
  </tr>
 <?php if ($line['AltPhone1'] == '' || $line['AltPhone2'] == '' || $line['AltPhone3'] == '') {  } else { ?> 
<tr>
    <td>Alternate Phone:</td>
    <td><?php echo $line['AltPhone1']; echo '-'; echo $line['AltPhone2']; echo '-'; echo $line['AltPhone3']; ?></td>
  </tr>
<?php } ?>
  <tr>
    <td>Lead Created:</td>
    <td><?php echo $line['datecreated']; ?></td>
  </tr>
<?php if($line['emailsent'] == 1){  ?> <tr>
    <td>Follow-Up Email Sent:</td>
    <td><?php echo $line['followupsent']; ?></td>
  </tr>
  <?php } ?>
  <tr>
    <td>Arrival Date:</td>
    <td><?php echo $line['arrival']; ?></td>
  </tr>
  <tr>
    <td>Departure Date:</td>
    <td><?php echo $line['departure']; ?></td>
  </tr>
  <?php if ($line['adults'] == ''){  } else { ?>
  <tr>
   <td>Adults:</td>
    <td><?php echo $line['adults']; ?></td>
  </tr><?php } ?>
 <?php if ($line['child'] == ''){  } else { ?>
  <tr>
    <td>Children:</td>
    <td><?php echo $line['child']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['area'] == ''){  } else { ?>
 <tr>
    <td>Requested Area:</td>
    <td><?php echo $line['area']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['budget'] == ''){  } else { ?>
 <tr>
    <td>Budget:</td>
    <td><?php echo $line['budget']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['suggested'] == ''){  } else { ?>
 <tr>
    <td>Suggested Properties:</td>
    <td><?php echo $line['suggested']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['discount'] == ''){  } else { ?> 
<tr>
    <td>Discount Offered:</td>
    <td><?php echo $line['discount']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['promo'] == ''){  } else { ?> 
<tr>
    <td>Promo Code:</td>
    <td><?php echo $line['promo']; ?></td>
  </tr>
<?php } ?>
  <tr>
    <td>Lead Status:</td>
    <td><?php echo $line['status']; ?></td>
  </tr>
  <?php if ($line['notes'] == ''){  } else { ?>     
<tr>
    <td height="85">Additional Notes:</td>
    <td><?php echo $line['notes']; ?></td>
  </tr>
<?php } ?>
 <?php if ($line['resnum'] == ''){  } else { ?>  
<tr>
    <td>Reservation Number:</td>
    <td><?php echo $line['resnum']; ?></td>
</tr><?php } } ?>

</table>

    </td>
  </tr>
</table>

</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
            <a class="btn btn-primary" href="#">Button</a>
          </div>
        </div>
      </div>
    </div>

非常感谢您的帮助。
谢谢,斯科特

0sgqnhkj

0sgqnhkj1#

你所要求的不能在当前的设计中实现。您的答案将是循环您的db结果来创建几个modal(messy),或者使用ajax根据链接id检索modal数据。这里的答案就是一个很好的例子:使用jquery ajax从mysql检索数据

相关问题