简体   繁体   English

我想以表格形式显示来自循环的数据

[英]i want to display data which is coming from loop in a table form

My PHP Code is Given Below. 我的PHP代码在下面给出。

 <?php  
     for($i=0;$i<$max;$i++){
        $pid=$_SESSION['cart'][$i]['productid'];
        $sid=$_SESSION['cart'][$i]['STOREID'];
        $q=$_SESSION['cart'][$i]['qty']; 
        $Product=get_product_name($pid,$sid);
        $price=get_price($pid,$sid);
        echo $Product;
 ?>
      <table border='1'>
         <tr>
           <th>Ordered Product</th
           <th>Price</th>
           <th>Quantity</th>
        </tr>   
     </table>

I want to display the product in table under Ordered Product. 我想在订购产品下的表中显示产品。

It depends on which format you're willing to display. 这取决于您愿意显示的格式。 Let me show an example: 让我举一个例子:

 <table border='1'> <thead> <tr> <th>Ordered Product</th> <th>Price</th> <th>Quantity</th> </tr> </thead> <tbody> <?php for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $sid=$_SESSION['cart'][$i]['STOREID']; $q=$_SESSION['cart'][$i]['qty']; $Product=get_product_name($pid,$sid); $price=get_price($pid,$sid); ?> <tr> <th><?php echo $product ?></th> <th><?php echo $price ?></th> <th><?php echo $q ?></th> </tr> <?php } ?> </tbody> </table> 

One suggestion that I'd like to provide is to avoid writing HTML codes within echo. 我想提供的一项建议是避免在echo中编写HTML代码。 It's the best if you keep the PHP and HTML codes separeted. 最好将PHP和HTML代码分隔开。

Hope this helps! 希望这可以帮助!

Peace! 和平! xD xD

暂无
暂无

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

相关问题 我想使用ajax编辑while循环中出现的品牌名称,数据在输入type =“ text”中 - I want to edit the Brand name which is coming in while loop using ajax the data is in input type="text 我想在表格中显示以下数据 - I want to display the following data in table 我在 Div 中有表单和循环中的 Div 以显示保存的数据,我想检查是否在任何 From any fiedls 中更改了我可以检测到更改 - I have Form in Div & that Div in loop to display saved data, I want to check if in any From any fiedls is changed i can detect the changes 我正在使用 selectpicker 我想编辑来自数据库的数据,但所有选项都已被选中 - I am using selectpicker I want to edit the data coming from the database, but all options are coming already selected 我想连接数据并显示一个表中的所有记录和另一个表中的一个记录 - I want to join data and display all records from one table and just one record from another table 我想在循环中重复相同的形式 x 次并用树枝显示它 - I want to repeat the same form x times in a loop and display it with twig 使用会话从表中提取更多数据(我想以配置文件格式显示用户的数据) - pulling more data from a table using a session(I want to display a user's data in profile format) 我想将数据从一种表格发送到许多表中,但是我选择的表却没有其他 - I want to send data into many Table from one FORM but my selected table not others 我想将数据从单个表单插入到多个表中,两个表都包含关系 - I want to insert data from a single form into multiple table both table contains relations 我想从一个表中选择名称并显示在我的页面中 - i want select name form one table and display in my page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM