Page 1 of 1

Table in HTML box

PostPosted: Tue Jan 08, 2019 10:57 pm
by Janusz
I'am trying to display table in HTML box.

I am testing it based on the following example. ... 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
$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));

      $no    = 1;
      $total    = 0;
      while ($row = mysqli_fetch_array($query))
         $amount  = $row['amount'] == 0 ? '' : number_format($row['amount']);
         echo '<tr>
               <td>'. date('F d, Y', strtotime($row['date'])) . '</td>
         $total += $row['amount'];

Re: Table in HTML box

PostPosted: Tue Jan 08, 2019 11:26 pm
by kev1n
You can't run PHP code in an html object. You need to run the PHP in the Before Edit event and then pass the data to javascript or use ajax to retrieve data from the database.
( ... html-table)