Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Table in HTML box

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Table in HTML box

Unread post by Janusz »

I'am trying to display table in HTML box.

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++;
		}?>
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Table in HTML box

Unread post 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.
(https://stackoverflow.com/questions/518 ... html-table)
Post Reply