Want the PHP script to pull all data from the database and display it on screen. But can't find the most efficient method to display the records without using the $query_params variable as it generates an error with the parameters in but cannot run without an array?
//initial query
$query = "Select * FROM tbl_data";
//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));
}
And here is the display code
$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"] = array();
foreach ($rows as $row) {
$post = array();
$post["username"] = $row["username"];
$post["title"] = $row["title"];
$post["message"] = $row["message"];
I would be really grateful if you could help, thank you!