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

问题描述:

基本上,它在问题中说,我试图从我的数据库中获取数据,并使数据库中的每一行显示在一个HTML表中的新行。我认为我是在正确的轨道,但是当我在PhpStorm中查看我的代码时,它抛出一个错误,说需要参数$ query缺少。我不知道这个参数是什么意思,但错误显示在查询行:
$ result = mysqli_query(....

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>


文档 mysqli_query 在过程风格中使用时需要2个参数。我假设 $ connection 是您的mysqli链接尝试:

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");