It sounds strange even for me but basically what i need is to include a php file inside an echo. Unfortunately i can't end the echo before include and continue it after that because all of that is part of an while statement.
And if if i do it like in the code below, in html that is seen as a comment.
Hope you can help me figured it out.
<?php
include('connect.php');
$nrcrt=1;
$sql="SELECT Cod, Nume, Categorie, Tumb, Tabel, Descriere FROM produse";
$sqlcateg="SELECT categ FROM categorii";
$resultcateg=$conn->query($sqlcateg);
$result=$conn->query($sql);
if($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{
echo '<tr>
<td>'.$nrcrt.'</td>
<td>'.$row['Cod'].'
<script type="text/javascript">
function editcod'.$nrcrt.'() {
var x = document.getElementById("fieldscod'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<br> <br>
<button onclick="editcod'.$nrcrt.'()">Editare</button>
<br>
<div id="fieldscod'.$nrcrt.'"hidden><input type="text" id="fieldupdatecod" value="'.$row['Cod'].'">
<br>
<input id="updatecod" type="submit" value="Update"></div>
</td>
<td>'.$row['Nume'].'
<script type="text/javascript">
function editnume'.$nrcrt.'() {
var x = document.getElementById("fieldsnume'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<br> <br>
<button onclick="editnume'.$nrcrt.'()">Editare</button>
<br>
<div id="fieldsnume'.$nrcrt.'" hidden><input type="text" id="fieldupdatenume" value="'.$row['Nume'].'">
<br>
<input id="updatenume" type="submit" value="Update"></div>
</td>
Here will be the problem, inside this .
<td>'.$row['Categorie'].'
<script type="text/javascript">
function editcateg'.$nrcrt.'() {
var x = document.getElementById("fieldscateg'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<br><br>
<button onclick="editcateg'.$nrcrt.'()">Editare</button>
<br>
<div id="fieldscateg'.$nrcrt.'" hidden>
<?php include("_include/php/readcateg.php");?>
<br>
<input id="updatecategorie" type="submit" value="Update"></div>
</td>
<td>'.$row['Descriere'].'
<script type="text/javascript">
function editdesc'.$nrcrt.'() {
var x = document.getElementById("fieldsdesc'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<br>
<button onclick="editdesc'.$nrcrt.'()">Editare</button>
<br><br>
<br>
<div id="fieldsdesc'.$nrcrt.'" hidden><textarea rows="5" id="fieldupdatedescriere">'.$row['Descriere'].'</textarea>
<br>
<input id="updatedescriere" type="submit" value="Update"></div>
</td>
<td><img src="_include/hfs/tumb/'.$row['Tumb'].'">
<script type="text/javascript">
function edittumb'.$nrcrt.'() {
var x = document.getElementById("fieldstumb'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<button onclick="edittumb'.$nrcrt.'()">Editare</button>
<br>
<div id="fieldstumb'.$nrcrt.'" hidden>
<input type="file" name="tumb" id="fileToUpload">
<input id="updatetumb" type="submit" value="Update"></div>
</td>
<td><img src="_include/hfs/tabel/'.$row['Tabel'].'">
<script type="text/javascript">
function edittabel'.$nrcrt.'() {
var x = document.getElementById("fieldstabel'.$nrcrt.'");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
};
</script>
<button onclick="edittabel'.$nrcrt.'()">Editare</button>
<br>
<div id="fieldstabel'.$nrcrt.'" hidden>
<input type="file" name="tabel" id="fileToUpload">
<input id="updatetabel" type="submit" value="Update"></div>
</td>
<td>
<input id="sterge" type="submit" value="Sterge">
</td>
</tr>';
$nrcrt=$nrcrt+1;
}
}
else
{ echo "0 results";}
?>
You should create a full string text with php include and depended scripts as a string init then eval it.
For example:
$str = '
<div>
<?php include("_include/php/readcateg.php");?>
<?php echo $var; ?>
</div>';
echo eval($str);