久久久久久久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 結果

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

      <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 結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                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ù)來在表中顯示查詢結果.我沒有自己構建任何表格,我希望它使用 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)在,我正確顯示了所有表格列標題,并獲得了正確數(shù)量的內(nèi)容行,但我無法使用數(shù)據(jù)庫中的實際數(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!

                推薦答案

                從同一個結果集中獲取數(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>
                

                測試結果

                您可以看到我如何將數(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

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

                You can also make them into separate functions.

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

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(liá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 準備好的語句問題)
                mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                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在线 | 午夜无遮挡 | 午夜免费在线 | 日本美女性生活 | 三级在线观看 | 黄色一级片网站 | 国产美女视频网站 | 午夜88 | 国产一级片免费观看 | 亚洲激情欧美 | 久久久免费看 | 亚洲欧美日韩国产精品 | 红桃av在线 | 亚洲欧美日韩色图 | 国产成人精品一区二区三区视频 | 日本午夜网站 | 亚洲精品视频免费在线观看 | 三级中文字幕 | 国产日韩欧美亚洲 | 亚洲美女一区 | 亚洲性视频 | 一级做a爰片久久毛片潮喷 视频一二区 | 性做久久久久久久免费看 | 久久草视频 | 日韩专区在线 | 免费久久久 | 欧美天堂在线 | 欧美理论片在线观看 | 国产中文字幕视频 | 久久视频在线免费观看 | 少妇视频网站 | 色八区 | 日韩高清在线 | 日韩av专区 | 人人草人人草 | 亚洲免费二区 | 欧美 日韩 国产 成人 在线 | 青娱乐福利视频 | 无套内谢的新婚少妇国语播放 | 欧美xxxx性 |