Table in HTML box

Questions related to customising nuBuilder Forte with Javascript or PHP.

Table in HTML box

Postby Janusz » Tue Jan 08, 2019 10:57 pm

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'];
Posts: 307
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Table in HTML box

Postby kev1n » Tue Jan 08, 2019 11:26 pm

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)
Posts: 777
Joined: Mon Oct 15, 2018 2:13 am

Return to Custom Code