drkwpgrdb092239314 2014-02-24 21:18
浏览 131
已采纳

如何使用php在html表中显示MySQL数据库中的数据

Basically as it says in the question i am trying to take data from my database and have each row in the database display in a new row in a HTML table. I thought i was on the right track but when viewing my code in PhpStorm it throws up an error saying required parameter $query missing. I'm not sure where this parameter is meant to be but the error is showing up on the query line: $result = mysqli_query(....

<table cellpadding="0" cellspacing="0" width="100%" class="sortable">

                        <thead>
                            <tr>
                                <th>Project title</th>
                                <th>Start Date</th>
                                <th>Acc Manager</th>
                                <th>Designer</th>
                                <th>Stage</th>
                                <td>&nbsp;</td>
                            </tr>
                        </thead>

                        <tbody>
<?php
      function list_projects() {

          global $connection;

      $output = "";
      $result = mysqli_query("SELECT * FROM projects ORDER BY project_title ASC");
      while ($row = mysqli_fetch_array($result)){
      $output .= '
      <tr>
      <td>' . $row['project_title'] . '</td>
      <td>' . $row['start_date'] . '</td>                                                   
      <td>' . $row['acc_manager'] . '</td>
      <td>' . $row['designer'] . '</td>
      <td>' . $row['stage'] . '</td>                                    
      </tr>';
      }

      return $output;

     }
?>
</tbody>
</table>
  • 写回答

3条回答 默认 最新

  • dongqufi82315 2014-02-24 21:22
    关注

    As stated in the docs. mysqli_query takes 2 parameters when used in a procedural style. I'm assuming $connection is your mysqli link Try:

    $result = mysqli_query($connection, "SELECT * FROM projects ORDER BY project_title ASC");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)