久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='JGLzM'><style id='JGLzM'><dir id='JGLzM'><q id='JGLzM'></q></dir></style></legend>

    <small id='JGLzM'></small><noframes id='JGLzM'>

  1. <i id='JGLzM'><tr id='JGLzM'><dt id='JGLzM'><q id='JGLzM'><span id='JGLzM'><b id='JGLzM'><form id='JGLzM'><ins id='JGLzM'></ins><ul id='JGLzM'></ul><sub id='JGLzM'></sub></form><legend id='JGLzM'></legend><bdo id='JGLzM'><pre id='JGLzM'><center id='JGLzM'></center></pre></bdo></b><th id='JGLzM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JGLzM'><tfoot id='JGLzM'></tfoot><dl id='JGLzM'><fieldset id='JGLzM'></fieldset></dl></div>

      <bdo id='JGLzM'></bdo><ul id='JGLzM'></ul>
    1. <tfoot id='JGLzM'></tfoot>
    2. PHP/MySQL 按列分組結果

      PHP/MySQL group results by column(PHP/MySQL 按列分組結果)
          <tbody id='wtMnM'></tbody>
          <bdo id='wtMnM'></bdo><ul id='wtMnM'></ul>
          <tfoot id='wtMnM'></tfoot>
          <i id='wtMnM'><tr id='wtMnM'><dt id='wtMnM'><q id='wtMnM'><span id='wtMnM'><b id='wtMnM'><form id='wtMnM'><ins id='wtMnM'></ins><ul id='wtMnM'></ul><sub id='wtMnM'></sub></form><legend id='wtMnM'></legend><bdo id='wtMnM'><pre id='wtMnM'><center id='wtMnM'></center></pre></bdo></b><th id='wtMnM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wtMnM'><tfoot id='wtMnM'></tfoot><dl id='wtMnM'><fieldset id='wtMnM'></fieldset></dl></div>

          <legend id='wtMnM'><style id='wtMnM'><dir id='wtMnM'><q id='wtMnM'></q></dir></style></legend>

                <small id='wtMnM'></small><noframes id='wtMnM'>

                本文介紹了PHP/MySQL 按列分組結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                為了盡可能少的保留SQL語句,我想從MySQL做select set:

                in order to keep as few SQL statements as possible, I want to do select set from MySQL:

                SELECT * FROM products WHERE category IN (10,120,150,500) ORDER BY category,id;
                

                現在,我有以下方式的產品列表:

                Now, I have list of products in following manner:

                CATEGORY
                 - product 1
                 - product 2
                CATEGORY 2
                 - product 37
                ...
                

                處理 MySQL 結果的最佳和最有效的方法是什么?

                What's the best and most efficent way to process MySQL result?

                我認為類似(偽 PHP)

                I thought something like (pseudo PHP)

                foreach ($product = fetch__assoc($result)){
                  $products[$category][] = $product;
                }
                

                然后在輸出時,做foreach循環:

                and then when outputting it, do foreach loop:

                foreach($categories as $category){
                  foreach($products[$category] as $product){
                    $output;
                  }
                }
                

                這是最好的,還是像mysql_use_groupby之類的神奇東西?

                Is this the best, or is something magical like mysql_use_groupby or something?

                推薦答案

                就像 mluebke 評論的那樣,使用 GROUP 意味著您只能獲得每個類別的一個結果.根據您提供的列表作為示例,我認為您想要這樣的東西:

                Like mluebke commented, using GROUP means that you only get one result for each category. Based on the list you gave as an example, I think you want something like this:

                $sql = "SELECT * FROM products WHERE category IN (10,120,150,500) GROUP BY category ORDER BY category, id";
                $res = mysql_query($sql);
                
                $list = array();
                while ($r = mysql_fetch_object($res)) {
                  $list[$r->category][$r->id]['name'] = $r->name;
                  $list[$r->category][$r->id]['whatever'] = $r->whatever;
                  // etc
                }

                然后遍歷數組.示例:

                foreach ($list as $category => $products) {
                  echo '<h1>' . $category . '</h1>';
                
                  foreach ($products as $productId => $productInfo) {
                    echo 'Product ' . $productId . ': ' . $productInfo['name'];
                    // etc
                  }
                
                }

                這篇關于PHP/MySQL 按列分組結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <bdo id='YCwRj'></bdo><ul id='YCwRj'></ul>

                    <small id='YCwRj'></small><noframes id='YCwRj'>

                      <tbody id='YCwRj'></tbody>
                        1. <legend id='YCwRj'><style id='YCwRj'><dir id='YCwRj'><q id='YCwRj'></q></dir></style></legend>

                        2. <i id='YCwRj'><tr id='YCwRj'><dt id='YCwRj'><q id='YCwRj'><span id='YCwRj'><b id='YCwRj'><form id='YCwRj'><ins id='YCwRj'></ins><ul id='YCwRj'></ul><sub id='YCwRj'></sub></form><legend id='YCwRj'></legend><bdo id='YCwRj'><pre id='YCwRj'><center id='YCwRj'></center></pre></bdo></b><th id='YCwRj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YCwRj'><tfoot id='YCwRj'></tfoot><dl id='YCwRj'><fieldset id='YCwRj'></fieldset></dl></div>
                          <tfoot id='YCwRj'></tfoot>

                          主站蜘蛛池模板: 日韩电影一区 | 日韩中文一区 | 极品久久 | 在线免费观看成年人视频 | 久久久久久久久一区 | 超碰在线网站 | 欧美综合国产精品久久丁香 | 国产欧美一区二区三区在线看 | 一级黄色绿像片 | 精品国产1区2区3区 一区二区手机在线 | 中文字幕一二三区 | www.久久久 | 国产视频中文字幕 | 97人人澡人人爽91综合色 | 成人午夜影院 | 欧美精品免费观看二区 | 在线观看www视频 | 国产精品视频一二三 | 久久久免费精品 | 色在线视频网站 | 日本久久久久久久久 | 美女视频一区 | 欧美一区2区三区4区公司二百 | 免费精品一区 | 欧美一区二区三区在线播放 | 日韩在线视频一区二区三区 | 国产美女一区二区 | 成人亚洲一区 | 国产高清精品网站 | 精品国产乱码久久久久久88av | 国产三区视频在线观看 | 午夜爱爱毛片xxxx视频免费看 | 国产精品久久久久久久久久99 | 亚洲精品大片 | 亚洲精品一区二区另类图片 | 亚洲国产视频一区二区 | 国产成人精品久久二区二区 | 中文字幕在线不卡播放 | 国产免费xxx | www.久久 | 九九九精品视频 |