Currently I'm learning about PHP and database, I wrote the script below to display the image as background for my div element, but the output is actually nothing! the error is from the line:
echo "<div class=\"post\" style='background-image: url('\"<?php echo $data[Image];\"?>')'";?>
The quotes mess up! Can someone tell me how to correct this? I tried to change double quotes to single quotes, but still doesn't work at all.
This is my full script:
<div class="dashboardA">
<?php
$con = mysqli_connect("localhost", "Dave", "password");
if (!$con){
die ("Could not connect to database: " . mysqli_connect_error());
}
mysqli_select_db($con, "my_blog");
$sql = mysqli_query($con, "select * from article");
while ($data=mysqli_fetch_array($sql)){
echo "<div class=\"post\" style='background-image: url('\"<?php echo $data[Image];\"?>')'";?>
<?php echo "<p>" . $data["Title"] . "</p>";
echo "<p>" . $data["Category"] . "</p>";
echo "<p>" . $data["Published"] . "</p>";
echo "</div>";
}
?>
</div>