I need help in inserting image path into arrays. Is it even possible? Firstly, I have created a table for accepting random comments from the user then inside that table I have a path for images that I want to call at the same time as the text. I have no problem displaying the texts such as username, password but when I add the path to it, it only displays the URL literally. How would I display the image?
Here is my PHP code:
<?php
require("admin.config.inc.php");
//initial query
$query = "Select * FROM adComments";
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
// Finally, we can retrieve all of the found rows into an array using fetchAll
$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"] = array();
foreach ($rows as $row) {
$post = array();
$post["post_id"] = $row["post_id"];
$post['img'] = 'http://www.stagconnect.com/StagConnect/admin/pictures/'.$row["image_name"];
$post["username"] = $row["username"];
$post["title"] = $row["title"];
$post["message"] = $row["message"];
$post["time"] = $row["time"];
//update our repsonse JSON data
array_push($response["posts"], $post);
}
// echoing JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No Post Available!";
die(json_encode($response));
}
?>
The only problem here is the post['img']
. It doesn’t display an image. What other method can I try? Any help will do.