Reputation: 201
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> </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>
Upvotes: 1
Views: 17503
Reputation: 196
Do you run the function?
echo list_projects();
(I know, silly question, but I dont see that you are doing it?)
Upvotes: 0
Reputation: 5424
You need to pass the $connection
into you mysqli_query()
function.
https://www.php.net/mysqli_query
$result = mysqli_query($connection, $query);
Upvotes: 1
Reputation: 6452
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");
Upvotes: 1