Page 1 of 1

PHP inside HTML

Posted: Sun Mar 10, 2019 11:52 pm
by Janusz
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>

Re: PHP inside HTML

Posted: Wed Mar 13, 2019 8:28 am
by kev1n
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?

Re: PHP inside HTML

Posted: Wed Mar 13, 2019 5:37 pm
by Janusz
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>