PHP inside HTML

Questions related to customising nuBuilder Forte with Javascript or PHP.

PHP inside HTML

Postby Janusz » Mon Mar 11, 2019 8:22 am

Hi,
I wanted to execute some php code inside the HTML but did not succeed.
So using the most basic code - how to place it inside nuBuilder to have it working.

Code: Select all
<!DOCTYPE html>
<html>
<body>
<p>First try with php:</p>

<?php
echo "My first PHP script!";
?>

</body>
</html>
Janusz
 
Posts: 220
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: PHP inside HTML

Postby kev1n » Wed Mar 13, 2019 4:58 pm

PHP code isn't interpreted when inserted into a HTML object. When you view the source of the page it still shows the php code.
What would you like to display?
kev1n
 
Posts: 242
Joined: Mon Oct 15, 2018 2:13 am

Re: PHP inside HTML

Postby Janusz » Thu Mar 14, 2019 2:07 am

Hi Kev1n,
I wanted to display some real photos of product inside the HTML box (so only photos for choosen product).
Photos are stored on server in one folder.
Names of photos and assignements to products are stored in mySQL table.
So depanding on the product I wanted to generate list of photos in mySQL and later to transfer it to nuBuilder JS to display them using directly path to photos.
So the biggest difficulty I had it was - how to tranfer mySQL data to JS or HTML inside nuBuilder.

But anyway finally I implemented following solutions which works very well now.

I use Object/Display field (name: pic_list) where the following query is placed (and read data from mySql)
Code: Select all
select    fot_picture from fotos_all where fot_part_nr='#par_sample_id_number#'

Additional issue was that in such field only the first row is placed. So in Mysql I am generating view with long rows and in every row I have a list of all photos attached to one product.
Code: Select all
GROUP_CONCAT( DISTINCT .... 


later in JS I read the data from the display field and generate list of photos for HTML field
Code: Select all
var lista = $('#pic_list').val();
var temp=  "arr =['"+lista+"']";
var arr = eval(temp);
var holder = document.getElementById("holder");
for(var i=0; i < arr.length; i++)
holder.innerHTML += "<img src='./uploads/"+arr[i]+"' style='width:300px;'>";

and finally in HTML field just following short code is placed which displays all selected photos one after the other:
Code: Select all
<div id="holder"></div>
Janusz
 
Posts: 220
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland


Return to Custom Code