i’ve built an application whereby i would upload an image onto my server allong with its info stored on my db which works fine. I am now trying to display my images and info together in my homepage.html.php file but when try to do this nothing is displayed.
What i don’t understand is in the book, ‘Build Your Own Database Driven Website using PHP & MYSQL 4th ed’ there are many examples in this book e.g chapter 7p223/4 which uses a while loop to get the results from the db and and uses the include ‘jokes.html.php’ code to display their results, it seems to work there but when i do it myself nothing appears, why? What am i missing?
include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
$result = mysqli_query($link, "SELECT * FROM image_detail");
$error = 'Error fetching image data from database';
while ($row = mysqli_fetch_array($result))
$images = array('Filename' => $row['Filename'], 'Description' => $row['Description'], 'Category' => $row['Category']);
Forgive me, I’ve got the concept behind include pretty wrong. I’ve just realised how it works - it seems to me that it includes them as if there is an invisible ?> added right before the inclusion, and an <?php right after it.
messy reayll? But why does the book have it this way? having all the logic in the index.php file and doing all the display stuff in the .html.php file because obviously i’m trying to use the same technique onto my project. To me it seems reasonable
When you include that HTML in your PHP script it’s just as if you’d copy-pasted it straight into the PHP script. It will therefore cause all sorts of problems because PHP doesn’t understand HTML and you’re adding inside <?php ?> tags. If you put a ?> tag right at the beginning of the HTML, then it should work. But it’s a rather messy way of doing this. You might as well just have it all in the same .php file.
I added a ?> at the beginning of my html i.e ?><html xmlns="http://www.w3… which i assume is what you are referring to right? if so, after adding that, all i see is the ?> on my web browser not my images unless i missunderstood you.