I am testing it based on the following example.
http://webdevzoom.com/display-mysql-dat ... using-php/
There is no issue with the HTML part and I can display the table itself,
But I am not able to properly connect and read data from the table.
Can you please give me some advice how to replace the following part of code in order to be able to run it from nuBuilder HTML box?
Code: Select all
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = ''; // Password
$db_name = 'tutorial'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = 'SELECT *
FROM sales';
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{
$amount = $row['amount'] == 0 ? '' : number_format($row['amount']);
echo '<tr>
<td>'.$no.'</td>
<td>'.$row['name'].'</td>
<td>'.$row['item'].'</td>
<td>'. date('F d, Y', strtotime($row['date'])) . '</td>
<td>'.$amount.'</td>
</tr>';
$total += $row['amount'];
$no++;
}?>