本文介绍了在从另一个foreach表中调用的模式中加载foreach表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格在英寸的模态。我从一个foreach表格加载模态。我相信我的代码是正确的,但我不知道它为什么显示在一个有趣的方式。这是我的代码,当我运行这段代码时,这是我得到的结果。点击链接查看图片

 < tbody> 
<?php
$ count = 1;
$ notarray = DataDB :: getInstance() - > select_from_where('order_collective','user_id',$ userid);
foreach($ notarray as $ row):
$ address = $ row ['appartment']。,。$ row ['address']。,。$ row ['city' ] $行[ '状态'] $行[ '里程碑']。。 。
?>
< tr>
< td><?php echo $ count ++;?>< / td>
< td><?php echo $ row ['trackingnumber'];?>< / td>
< td><?php echoNGN.number_format($ row ['price'],2);?>< / td>
< td><?php echo $ address;?>< / td>
< td><?php echo $ row ['order_date'];?>< / td>
< td><?php echo DataDB :: getInstance() - > get_name_from_id('name','delivery_status','delivery_status_id',$ row ['delivery_status']);?>< / TD>

< td>
< div class =btn-group>
< button type =buttonclass =btn btn-infodata-toggle =modaldata-target =#myVie<?php echo $ row ['trackingnumber']?>> ;查看< /按钮>

< / div>
< / td>
< / tr>
<?php include('order_history_modal.php'); ?>
<?php endforeach;?>
< / tbody>
< div id =myVie<?php echo $ row ['trackingnumber']?> class =modal faderole =dialog>
 <! - 模态内容 - > 
< div class =modal-content>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modal>& times;< / button>
< h4 class =modal-title>模态头< / h4>
< / div>
< div class =modal-body>

< div class =table-responsive>
< table class =table>
< thead>
< tr>
< th>项目< / th>
< th>数量< / th>
Price< th>
< / tr>
< / thead>
< tbody>
<?php
$ notal = DataDB :: getInstance() - > select_from_where('order_details','trackingnumber',$ row ['trackingnumber']);
foreach($ notal as $ rol):
$ prrname = DataDB :: getInstance() - > get_name_from_id('product_name','product','product_id',$ rol ['product_id']] );?>
< tr>
< td><?php echo $ prrname?>< / td>
< td><?php echo $ rol ['quantity']?>< / td>
< td><?php echoNGN.number_format($ rol ['price'],2);?>< / td>
< / tr>
<?php endforeach; ?>
< / tbody>
< / table>
< p>< / p>
< / div>
< / div>
< div class =modal-footer>
< button type =buttonclass =btn btn-defaultdata-dismiss =modal>关闭< / button>
< / div>
< / div>

< / div>
< / div>

< / div>
< / div>


解决方案

使用像这样。

 < table class =table> 
< thead>
< tr>
< th>#< / th>
< th> Track Number< / th>
Price< th>
< th>地址< / th>
< th>订单日期< / th>
< th>状态< / th>
< th>拍卖< / th>
< / tr>
< / thead>


< tbody>
<?php
$ count = 1;
$ notarray = DataDB :: getInstance() - > select_from_where('order_collective','user_id',$ userid);
foreach($ notarray as $ row):
$ address = $ row ['appartment']。,。$ row ['address']。,。$ row ['city' ] $行[ '状态'] $行[ '里程碑']。。 。
?>
< tr>
< td><?php echo $ count ++;?>< / td>
< td><?php echo $ row ['trackingnumber'];?>< / td>
< td><?php echoNGN.number_format($ row ['price'],2);?>< / td>
< td><?php echo $ address;?>< / td>
< td><?php echo $ row ['order_date'];?>< / td>
< td><?php echo DataDB :: getInstance() - > get_name_from_id('name','delivery_status','delivery_status_id',$ row ['delivery_status']);?>< / TD>
< td>
< div class =btn-group>
< button type =buttonclass =btn btn-infodata-toggle =modaldata-target =#myVie<?php echo $ row ['trackingnumber']?>> ;查看< /按钮>
< / div>
<?php include('order_history_modal.php'); ?>
< / td>
< / tr>
<?php endforeach;?>
< / tbody>
< / table>

order_history_modal.php

 < div id =myVie<?php echo $ row ['trackingnumber']?> class =modal faderole =dialog> 
< div class =modal-content>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modal>& times;< / button>
< h4 class =modal-title>模态头< / h4>
< / div>
< div class =modal-body>
< div class =table-responsive>
< table class =table>
< thead>
< tr>
< th>项目< / th>
< th>数量< / th>
Price< th>
< / tr>
< / thead>
< tbody>
<?php
$ notal = DataDB :: getInstance() - > select_from_where('order_details','trackingnumber',$ row ['trackingnumber']);
foreach($ notal as $ rol):
$ prrname = DataDB :: getInstance() - > get_name_from_id('product_name','product','product_id',$ rol ['product_id']] );?>
< tr>
< td><?php echo $ prrname?>< / td>
< td><?php echo $ rol ['quantity']?>< / td>
< td><?php echoNGN.number_format($ rol ['price'],2);?>< / td>
< / tr>
<?php endforeach; ?>
< / tbody>
< / table>
< / div>
< / div>
< div class =modal-footer>
< button type =buttonclass =btn btn-defaultdata-dismiss =modal>关闭< / button>
< / div>
< / div>
< / div>

< pre-class =snippet-code-html lang-html prettyprint-override< ;脚本src =https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js>< / script><! - 最新编译和缩小的CSS - >< link rel =stylesheethref =https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.cssintegrity =sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va + PmSTsz / K68vbdEjh4ucrossorigin = anonymous><! - 可选主题 - >< link rel =stylesheethref =https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min .cssintegrity =sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl / Spcrossorigin =anonymous><! - 最新编译和缩小的JavaScript - >< script src =https://maxcdn.bootstrapcdn.com/bootstrap /3.3.7/js/bootstrap.min.jsintegrity =sha384-Tc5IQib027qv yjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txacrossorigin =anonymous>< / script>< table class =table> < THEAD> < TR> <的第i;#< /第> < th> Track Number< / th> <的第i;价格< /第> <第>地址< /第> < th>订单日期< / th> <的第i;状态< /第> <的第i;拍卖与LT; /第> < / TR> < / THEAD> < TBODY> < TR> < TD→1< / TD> < TD>试验< / TD> < TD>试验< / TD> < TD>试验< / TD> < TD>试验< / TD> < TD>试验< / TD> < TD> < div class =btn-group> < button type =buttonclass =btn btn-infodata-toggle =modaldata-target =#myVie1>查看< /按钮> < / DIV> < div id =myVie1class =modal faderole =dialog> <! - 模态内容 - > < div class =modal-content> < div class =modal-header> < button type =buttonclass =closedata-dismiss =modal>& times;< / button> < h4 class =modal-title>模态标头< / h4> < / DIV> < div class =modal-body> < div class =table-responsive> < table class =table> < THEAD> < TR> <的第i;项目< /&第GT; <的第i;数量< /第> <的第i;价格< /第> < / TR> < / THEAD> < TBODY> < TR> < TD>试验< / TD> < TD>试验< / TD> < TD>试验< / TD> < / TR> < / tbody的> < /表> < / DIV> < / DIV> < div class =modal-footer> < button type =buttonclass =btn btn-defaultdata-dismiss =modal>关闭< /按钮> < / DIV> < / DIV> < / DIV> < / TD> < / TR> < / tbody>< / table>


i have a modal with a table in in. i load the modal from a foreach table. i believe my code is right but i dont know why it displays in a funny way. this is my code and when i run this code this is the result i get. click on the link to view the image image

 <tbody>
           <?php
                        $count = 1; 
                        $notarray = DataDB::getInstance()->select_from_where('order_collective','user_id',$userid);
                        foreach($notarray as $row):
                        $address = $row['appartment'].",".$row['address'].",".$row['city'].",".$row['state'].".".$row['landmark'];
                        ?>
                    <tr>
                        <td><?php echo $count++;?></td>
                        <td><?php echo $row['trackingnumber'];?></td>
                        <td><?php echo "NGN ".number_format($row['price'], 2);?></td>
                        <td><?php echo $address;?></td>
                        <td><?php echo $row['order_date'];?></td>
                        <td><?php echo DataDB::getInstance()->get_name_from_id('name','delivery_status','delivery_status_id',$row['delivery_status']);?></td>

              <td>
                <div class="btn-group">
                     <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myVie<?php echo $row['trackingnumber'] ?>">View</button>

                </div>
              </td>
            </tr>
             <?php include ('order_history_modal.php'); ?>
            <?php endforeach;?>
            </tbody>
 <!-- ORDER HISTORY Modal content-->
  <div id="myVie<?php echo $row['trackingnumber'] ?>" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Modal Header</h4>
  </div>
  <div class="modal-body">

           <div class="table-responsive">
                      <table class="table">
<thead>
  <tr>
    <th>Item</th>
    <th>Quantity</th>
    <th>Price</th>
  </tr>
</thead>
<tbody>
<?php 
        $notal = DataDB::getInstance()->select_from_where('order_details','trackingnumber',$row['trackingnumber']);             
        foreach($notal as $rol):
        $prrname = DataDB::getInstance()->get_name_from_id('product_name','product','product_id',$rol['product_id']);?>
  <tr>
    <td><?php echo $prrname ?></td>
    <td><?php echo $rol['quantity'] ?></td>
    <td><?php echo "NGN ".number_format($rol['price'], 2);?></td>
  </tr>
 <?php endforeach; ?>
</tbody>
 </table>
                        <p></p>
                      </div> 
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>

</div>
</div>

</div>
</div>
解决方案

Use like this.

<table class="table">
    <thead>
        <tr>
            <th>#</th>
            <th>Track Number</th>
            <th>Price</th>
            <th>Address</th>
            <th>Order Date</th>
            <th>Status</th>
            <th>Auction</th>
        </tr>
    </thead>


    <tbody>
    <?php
        $count = 1; 
        $notarray = DataDB::getInstance()->select_from_where('order_collective','user_id',$userid);
        foreach($notarray as $row):
        $address = $row['appartment'].",".$row['address'].",".$row['city'].",".$row['state'].".".$row['landmark'];
        ?>
    <tr>
        <td><?php echo $count++;?></td>
        <td><?php echo $row['trackingnumber'];?></td>
        <td><?php echo "NGN ".number_format($row['price'], 2);?></td>
        <td><?php echo $address;?></td>
        <td><?php echo $row['order_date'];?></td>
        <td><?php echo DataDB::getInstance()->get_name_from_id('name','delivery_status','delivery_status_id',$row['delivery_status']);?></td>
        <td>
        <div class="btn-group">
            <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myVie<?php echo $row['trackingnumber'] ?>">View</button>
        </div>
        <?php include ('order_history_modal.php'); ?>
        </td>
    </tr>  
    <?php endforeach;?>
</tbody>
</table>

order_history_modal.php

<div id="myVie<?php echo $row['trackingnumber'] ?>" class="modal fade" role="dialog">
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                      <tr>
                        <th>Item</th>
                        <th>Quantity</th>
                        <th>Price</th>
                      </tr>
                    </thead>
                    <tbody>
                <?php 
                $notal = DataDB::getInstance()->select_from_where('order_details','trackingnumber',$row['trackingnumber']);             
                foreach($notal as $rol):
                    $prrname = DataDB::getInstance()->get_name_from_id('product_name','product','product_id',$rol['product_id']);?>
                    <tr>
                    <td><?php echo $prrname ?></td>
                    <td><?php echo $rol['quantity'] ?></td>
                    <td><?php echo "NGN ".number_format($rol['price'], 2);?></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
                </table>
             </div> 
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
    </div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<table class="table">
	<thead>
    	<tr>
        	<th>#</th>
            <th>Track Number</th>
            <th>Price</th>
            <th>Address</th>
            <th>Order Date</th>
            <th>Status</th>
            <th>Auction</th>
        </tr>
    </thead>
    <tbody>
    	<tr>
        	<td>1</td>
            <td>test</td>
            <td>test</td>
            <td>test</td>
            <td>test</td>
            <td>test</td>
            <td>
            <div class="btn-group">
                 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myVie1">View</button>
            </div>
	        <div id="myVie1" class="modal fade" role="dialog">
             	<!-- Modal content-->
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Modal Header</h4>
                  </div>
                  <div class="modal-body">
					<div class="table-responsive">
                        <table class="table">
                            <thead>
                              <tr>
                                <th>Item</th>
                                <th>Quantity</th>
                                <th>Price</th>
                              </tr>
                            </thead>
                            <tbody>
                              <tr>
                                <td>test</td>
                                <td>test</td>
                                <td>test</td>
                              </tr>
                            </tbody>
                        </table>
                     </div> 
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                  </div>
                </div>
			</div>
            </td>
        </tr>
    </tbody>
</table>

这篇关于在从另一个foreach表中调用的模式中加载foreach表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:03