个性化阅读
专注于IT技术分析

连接表格并获取数据到手风琴/可折叠和表格

点击下载

我想通过连接从两个表中获取数据, 并在可折叠/可折叠的情况下显示类别, 在这些之下, 我想在与该类别相关的表中显示产品信息。我有代码, 但如屏幕截图所示, 我一次又一次获取一个类别和表数据, 请提供帮助。

在此处输入图片说明

在此处输入图片说明

<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM `wp_orderlist` 
JOIN wp_product_category ON 
wp_product_category.item_id=wp_orderlist.category 
where wp_product_category.item_id=wp_orderlist.category");

   foreach ( $result as $print){
                                   ?>
    <button class="collapsible"> <?php echo $print->category?>/button> 
    <div class="content">

   <table border="1">
   <tr>
   <th>Item Description</th>    
   <th>Packing Size</th>    
   <th>Cart</th>
   </tr>
    foreach ( $result as $print )   {

    echo '<tr>';
    echo '<td>'. $print->Item_Description.'</td>';
    echo '<td>'. $print->Packing.'</td>';
    echo '<td> <input type="submit" value="ADD"> </td>';
    echo '</tr>';
      } //ending nested loop
    echo '</tr> ';
     ?>            
   </table>
   </div>
   <?php }?>//ending main loop

#1


    <?php   // I find my solution to my problem
      global $wpdb;
      $result = $wpdb->get_results ( "SELECT * from wp_product_category  ");

       foreach ( $result as $print){
       $cat = $print->item_id;
       ?>
      <button class="collapsible"><?=$print->category  ?><span style="margin- 
      left:130px;"><?=$print->category  ?></span>  </button>

     <div class="content">
    <table border="1">
    <tr>
    <th>Item_ID</th>    
     <th>Item Description</th>  
     <th>Packing Size</th>  
        <th>Cart</th>
       </tr>
      <?php
       $result1 = $wpdb->get_results ( "SELECT * FROM wp_orderlist where 
       category_id = $cat ");
       foreach ( $result1 as $print1 )   {

      echo '<tr>';
      echo '<td>'. $print1->item_id.'</td>';
      echo '<td>'. $print1->Item_Description.'</td>';
      echo '<td>'. $print1->Packing.'</td>';
      echo '<td> <form method="post"> <input type="submit" name="add" 
     href="$print1->item_id" value="ADD"></form> </td>';
     echo '</tr>';
    }  
    } 

  echo '</tr> ';
   ?>            

  </table>
  </div>
  <?php } ?>
赞(0)
未经允许不得转载:srcmini » 连接表格并获取数据到手风琴/可折叠和表格

评论 抢沙发

评论前必须登录!