简体   繁体   English

如何将PHP的结果变量传递给bootstrap模态中的include.php

[英]How to pass a php while result variable to include.php located inside the bootstrap modal

I want pass a variable from php while to include.php inside the bootstrap modal. 我想从Bootstrap模态内的include.php传递一个php变量。 My php while is on the whileresult.php 我的php while在whileresult.php上

<?php
    $i=0;
    while ($i < $rows) {
        $title_books=mysql_result($result,$i,"title_books");
        $pages_books=mysql_result($result,$i,"pages_books");
        $author_books=mysql_result($result,$i,"author_books");
?>
<?php echo $title_books; ?>

after, there is a bootstrap modal and this there are a include.php 之后,有一个引导程序模态,这有一个include.php

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-1">
  <div class="btn-group">
    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <i class="fa fa-cog fa-2x" aria-hidden="true"></i><span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
      <li>
        <a href="#" data-toggle="modal" data-target="#modalShareBk">Book in library</a>
      </li>
    </ul>
  </div>
</div>

<!-- start modal with include.php -->
<div id="modalShareBk" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Your Books</h4>
      </div>
      <div class="modal-body">
        <?php include("include.php"); ?>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default btn-xs" data-dismiss="modal">
          <i class="fa fa-times-circle" aria-hidden="true"></i> Close
        </button>
      </div>
    </div>
  </div>
</div>

Now, how to pass the value of variable $title_books inside the include.php page? 现在,如何在include.php页面内传递变量$ title_books的值?

Thanks 谢谢

Simply echo out the values in the include file the scope of the variable will be there in include.php 只需回显包含文件中的值,变量范围将包含在include.php中

PS. PS。 Use require_once() instead of include() 使用require_once()代替include()

Edit 1: You need to change the whileresult.php code to something like this 编辑1:您需要将whileresult.php代码更改为如下所示

whileresult.php whileresult.php

<?php
$i=0;
$title_books = array();
$pages_books = array();
$author_books = array();
while ($i < $rows) {
    $title_books[$i]=mysql_result($result,$i,"title_books");
    $pages_books[$i]=mysql_result($result,$i,"pages_books");
    $author_books[$i]=mysql_result($result,$i,"author_books");
    $i++;
?>

include.php include.php

<?php
for($j=0;$j<$i;$j++)
{
   echo 'Book - '.$title_books[$j].' Pages - '.$pages_books[$j].'Author - '.$author_books[$j];
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM