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

时间:2022-10-21 23:37:42

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(....

基本上就像问题中说的,我试图从数据库中获取数据,并将数据库中的每一行显示在HTML表的新行中。我认为我做得对,但是当在PhpStorm中查看代码时,它会抛出一个错误,说需要参数$query缺失。我不确定,这个参数是错误是出现在查询行:由于美元= 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 个解决方案

#1


1  

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:

如文件中所述。mysqli_query在过程样式中使用时接受两个参数。我假设$connection是你的mysqli链接尝试:

$result = mysqli_query($connection, "SELECT * FROM projects ORDER BY project_title ASC");

#2


1  

You need to pass the $connection into you mysqli_query() function.

您需要将$连接传递给mysqli_query()函数。

http://us3.php.net/mysqli_query

http://us3.php.net/mysqli_query

$result = mysqli_query($connection, $query);

#3


0  

Do you run the function?

你运行这个函数吗?

echo list_projects();

(I know, silly question, but I dont see that you are doing it?)

(我知道,傻问题,但我没看到你这么做?)

#1


1  

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:

如文件中所述。mysqli_query在过程样式中使用时接受两个参数。我假设$connection是你的mysqli链接尝试:

$result = mysqli_query($connection, "SELECT * FROM projects ORDER BY project_title ASC");

#2


1  

You need to pass the $connection into you mysqli_query() function.

您需要将$连接传递给mysqli_query()函数。

http://us3.php.net/mysqli_query

http://us3.php.net/mysqli_query

$result = mysqli_query($connection, $query);

#3


0  

Do you run the function?

你运行这个函数吗?

echo list_projects();

(I know, silly question, but I dont see that you are doing it?)

(我知道,傻问题,但我没看到你这么做?)