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

  1. <tfoot id='joRCW'></tfoot>
    1. <legend id='joRCW'><style id='joRCW'><dir id='joRCW'><q id='joRCW'></q></dir></style></legend>

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

    2. <i id='joRCW'><tr id='joRCW'><dt id='joRCW'><q id='joRCW'><span id='joRCW'><b id='joRCW'><form id='joRCW'><ins id='joRCW'></ins><ul id='joRCW'></ul><sub id='joRCW'></sub></form><legend id='joRCW'></legend><bdo id='joRCW'><pre id='joRCW'><center id='joRCW'></center></pre></bdo></b><th id='joRCW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='joRCW'><tfoot id='joRCW'></tfoot><dl id='joRCW'><fieldset id='joRCW'></fieldset></dl></div>
        <bdo id='joRCW'></bdo><ul id='joRCW'></ul>
    3. 使用 PHP 在 HTML 表格中顯示 MySQL 結(jié)果

      Use PHP to Display MySQL Results in HTML Table(使用 PHP 在 HTML 表格中顯示 MySQL 結(jié)果)

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

            <bdo id='DhIjT'></bdo><ul id='DhIjT'></ul>
            • <tfoot id='DhIjT'></tfoot>

                  <tbody id='DhIjT'></tbody>
              1. <small id='DhIjT'></small><noframes id='DhIjT'>

              2. 本文介紹了使用 PHP 在 HTML 表格中顯示 MySQL 結(jié)果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                CodingBiz 更新:

                我把它放在我的代碼中:

                I'm putting this in my code:

                for($i=1;$i<=$numRows;$i++) {
                    $output .= '<tr>';
                    $row = $this->fetchAssoc($result);
                    $colRow = $this->fetchAssoc($colResult);
                    foreach($colRow as $colName) {
                        $output .= "<td>".$row[$colName]."</td>";
                    }
                    $output .= '</tr>';
                }
                

                代替

                for($i=1;$i<=$numRows;$i++) {
                    $output .= '<tr>';
                    $row = $this->fetchAssoc($result);
                    for($j=1;$j<=$colNumRows;$j++) {
                        $colRow = $this->fetchAssoc($colResult);
                        $output .= "<td>".$row[$colRow["COLUMN_NAME"]]."</td>";
                    }
                    $output .= '</tr>';
                }
                

                這有什么問題嗎?

                原帖:

                我正在 PHP 類中編寫一個函數(shù)來在表中顯示查詢結(jié)果.我沒有自己構(gòu)建任何表格,我希望它使用 PHP 完成所有工作.到目前為止,這是我的代碼:

                I'm writing a function in a PHP class to display the results of a query in a table. I'm not structuring any of the table myself, I want it everything to be done using PHP. Here is my code so far:

                function allResults($table,$cols) {
                    if(isset($cols)) {
                        $query = "SELECT $cols FROM $table";
                    }
                    else {
                        $query = "SELECT * FROM $table";
                    }
                    $result = $this->query($query);
                    $numRows =  $this->numRows($result);
                    $colQuery ="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='shareride'  AND TABLE_NAME='$table'";
                    $colResult = $this->query($colQuery);
                    $colNumRows = $this->numRows($colResult);
                
                    $output = '<table class="allResults">';
                    $output .= '<tr>';
                    for($i=1;$i<=$colNumRows;$i++) {
                        $colRow = $this->fetchAssoc($colResult);
                        $output .= "<td>".$colRow["COLUMN_NAME"]."</td>";
                    }
                    $output .= '</tr>';
                    for($i=1;$i<=$numRows;$i++) {
                        $output .= '<tr>';
                        $row = $this->fetchAssoc($result);
                        for($j=1;$j<=$colNumRows;$j++) {
                            $colRow = $this->fetchAssoc($colResult);
                            $output .= "<td>".$row[$colRow["COLUMN_NAME"]]."</td>";
                        }
                        $output .= '</tr>';
                    }
                    $output .= '</table>';
                    return $output;
                }
                

                如果不清楚,query指的是mysqli_querynumRows指的是mysqli_num_rows>fetchAssoc 指的是 mysqli_fetch_assoc.數(shù)據(jù)庫名稱是shareride".

                In case it is unclear, query refers to mysqli_query, numRows refers to mysqli_num_rows, and fetchAssoc refers to mysqli_fetch_assoc. The database name is "shareride."

                我知道我在這一行中遺漏了一些東西:

                I know I am missing something in this line:

                $output .= "<td>".$row[$colRow["COLUMN_NAME"]]."</td>";
                

                但我只是不知道它是什么.現(xiàn)在,我正確顯示了所有表格列標(biāo)題,并獲得了正確數(shù)量的內(nèi)容行,但我無法使用數(shù)據(jù)庫中的實(shí)際數(shù)據(jù)填充這些行.

                but I just don't know what it is. Right now, I get all the table column titles displayed correctly, and I get the correct number of content rows, but I just can't populate those rows with the actual data from the database.

                我錯過了什么?任何幫助將非常感激!

                What am I missing? Any help would be GREATLY appreciated!

                推薦答案

                從同一個結(jié)果集中獲取數(shù)據(jù)和列名

                Get the data and column names from the same result set

                  <?php
                  $i = 0;
                  $colNames = array();
                  $data = array();
                  while($row = ***_fetch_assoc($res)) //where $res is from the main query result not schema information
                  {
                     //get the column names into an array $colNames
                     if($i == 0) //make sure this is done once
                     {
                        foreach($row as $colname => $val)
                           $colNames[] = $colname;
                     }
                
                     //get the data into an array
                     $data[] = $row;
                
                     $i++;
                  }
                
                 ?>
                

                更新:@YourCommonSense 建議替換上面的代碼,它有效,簡單且更短 - 一種無需像我那樣循環(huán)即可獲取列名/數(shù)組鍵的方法

                  $data = array();
                  while($row = mysql_fetch_assoc($res))
                  {
                     $data[] = $row;
                  }
                
                  $colNames = array_keys(reset($data))
                

                繼續(xù):打印表格

                 <table border="1">
                 <tr>
                    <?php
                       //print the header
                       foreach($colNames as $colName)
                       {
                          echo "<th>$colName</th>";
                       }
                    ?>
                 </tr>
                
                    <?php
                       //print the rows
                       foreach($data as $row)
                       {
                          echo "<tr>";
                          foreach($colNames as $colName)
                          {
                             echo "<td>".$row[$colName]."</td>";
                          }
                          echo "</tr>";
                       }
                    ?>
                 </table>
                

                測試結(jié)果

                您可以看到我如何將數(shù)據(jù)檢索與表生成分離.它們現(xiàn)在相互依賴,您可以通過使用靜態(tài)數(shù)據(jù)填充數(shù)組來測試沒有數(shù)據(jù)庫的表生成

                You can see how I separated the data retrieval from table generation. They are dependent of each other now and you can test your table generation without the database by populating the arrays with static data

                你也可以把它們做成單獨(dú)的函數(shù).

                You can also make them into separate functions.

                這篇關(guān)于使用 PHP 在 HTML 表格中顯示 MySQL 結(jié)果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                Call to undefined function mysqli_result::num_rows()(調(diào)用未定義的函數(shù) mysqli_result::num_rows())
                PHP Prepared Statement Problems(PHP 準(zhǔn)備好的語句問題)
                mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結(jié)果)
                PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)
                <i id='iZJo8'><tr id='iZJo8'><dt id='iZJo8'><q id='iZJo8'><span id='iZJo8'><b id='iZJo8'><form id='iZJo8'><ins id='iZJo8'></ins><ul id='iZJo8'></ul><sub id='iZJo8'></sub></form><legend id='iZJo8'></legend><bdo id='iZJo8'><pre id='iZJo8'><center id='iZJo8'></center></pre></bdo></b><th id='iZJo8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iZJo8'><tfoot id='iZJo8'></tfoot><dl id='iZJo8'><fieldset id='iZJo8'></fieldset></dl></div>
                  • <small id='iZJo8'></small><noframes id='iZJo8'>

                  • <tfoot id='iZJo8'></tfoot>
                    1. <legend id='iZJo8'><style id='iZJo8'><dir id='iZJo8'><q id='iZJo8'></q></dir></style></legend>
                        <bdo id='iZJo8'></bdo><ul id='iZJo8'></ul>
                            <tbody id='iZJo8'></tbody>

                          主站蜘蛛池模板: 国产无套一区二区三区久久 | 久久久久久久久久久久久久av | 国产精品视频一二三区 | 国产高清精品在线 | 色综合桃花网 | 国产成人免费在线 | 欧美一级在线观看 | 91精品国产欧美一区二区成人 | 韩国成人在线视频 | 99热视| 老头搡老女人毛片视频在线看 | 日韩精品久久久久久 | 51ⅴ精品国产91久久久久久 | 一级黄色录像片子 | 日本精品999 | 丁香婷婷在线视频 | 日韩欧美三级 | 天天操天天干天天曰 | 欧美日韩成人在线 | 男人天堂久久 | 激情视频一区 | 免费一级黄色录像 | 99草免费视频 | 污污的网站在线观看 | 亚洲国产网站 | 91精品福利 | 欧洲高清转码区一二区 | 久久亚洲欧美日韩精品专区 | 国产精品一区久久久 | 久久一| 在线观看免费av网 | 亚洲精品乱码久久久久久按摩观 | 成人精品福利 | 成人激情视频网 | 国产精品不卡视频 | 精品91av| 国产成人精品一区二区三 | 日本高清视频在线播放 | 欧美5区| 蜜桃av鲁一鲁一鲁一鲁 | av免费网站在线观看 |