dsj0312 2016-07-13 04:10
浏览 99

根据查询结果显示不同的Div

Here what I got in view

enter image description here

I want to show it as Separate divs based on vendor name

enter image description here

How can i Group the vandor names and Show in different divs ?

  • 写回答

2条回答 默认 最新

  • dsfdsf48652 2016-07-13 04:57
    关注

    I don't know how the data is being stored/retrieved but here is how I might do such sorting - assuming the variable $rows is set contains an associative array of all rows (similar to the results of a basic database query) and assuming "vendor" is the column name for the vendors (TSZ, TSR, etc), "sku" is the name of the SKU column, and "store_price" is the name of the store price column:

    <?php
    
    $vendorData = [];
    
    foreach( $rows as $row ) {
        if( !isset($vendorData[$row['vendor']]) ) {
            $vendorData[$row['vendor']] = '';
        }
        $vendorData[$row['vendor']] .= '<div class="sku">' .
            $row['sku'] . '</div>' .
            '<div class="price">' . $row['store_price'] . '</div>';
    }
    
    foreach( $vendorData as $vendorName => $vendorHTML ) {
        echo '<div id="' . $vendorName . '" class="vendor">' .
            '<h3 class="name">' . $vendorName . '</h3>' .
            '<div class="data">' . $vendorHTML . '</div></div>';
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题