Mixing Php and Javascript to add data in div
Posted: 11 Apr 2017, 20:31
After a mysql select i want to add data to a div content, but script don't work..can you look above this and give me a suggestion?
Code: Select all
<?php
require('layout.php');
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `location`.`id` , `location`.`location` , `location`.`customer` , `area`.`id` , GROUP_CONCAT(area.id ORDER BY area.id SEPARATOR ', ')
FROM `location` , `area`
where `location`.`id`= `area`.`id_principal`
GROUP BY `location`.`location` ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$var = $row["GROUP_CONCAT(area.id ORDER BY area.id SEPARATOR ', ')"];
$location = $row['location'];
$each=explode(', ',$var);
echo '<div class="col-md-3">
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">'.$location.'</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" id="content">
The body of the box
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>';
foreach($each as $v){
$q=$conn->query("SELECT `area`.`id` AS `area_id22` , `area`.`area` , `area`.`id_principal` , `area_description`.`id` , `area_description`.`description` , `area_description`.`id_area`,GROUP_CONCAT(area_images.patch ORDER BY area_images.patch SEPARATOR ', ') FROM `area` , `area_description`, `area_images` WHERE `area`.`id` ='" . $v. "' AND `area_description`.`id_area` = `area`.`id` AND `area_images`.`id_area` = `area`.`id` GROUP BY `area`.`area` " );
foreach($q as $cat){
$area_id = $cat['area_id22'];
$area = $cat['area'];
$descriere = $cat['description'];
echo '
<script> var theDiv = document.getElementById("content");
theDiv.innerHTML += " <ul>area: '.$area.'</ul>
<ul>description '.$descriere.'</ul>"; </script>
';
}
}
}
}
else {
echo "0 results";
}
$conn->close();
?>