How to output php sql function in html?
60
I have a function in php which needs to display all records within the table. But I just can't seem to display them in HTML.
Here is my php code:
<?php
function display_products(){
$query = mysql_query("Select id, naam,prijs from product");
$data = array();
while ($row = mysql_fetch_assoc($result)){
array_push($data, $row);
}
return $data;
}?>
and here is my attempt to display the array of in my html:
<?php
$products = display_products();
foreach ($products as $product): ?>
<ul>
<li><?php echo $product['naam'] ?></li>
<li><?php echo $product['prijs'] ?></li>
</ul>
}
<?php endforeach; unset($product); ?>
Answer
Solution:
Try something like the following (don't forget to change the constants in mysqli_connect() function). Also, if you get familiar with this try to use PDO.