You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why can't we get fetch all data form table and just return that data, then in while reading data just pass that data into to json_encode something like this?
In models/Post.php
// Get Postspublicfunctionread() {
// Create query$query = 'SELECT c.name as category_name, p.id, p.category_id, p.title, p.body, p.author, p.created_at FROM ' . $this->table . ' p LEFT JOIN categories c ON p.category_id = c.id ORDER BY p.created_at DESC';
// Prepare statement$stmt = $this->conn->prepare($query);
// Execute query$stmt->execute();
return$stmt;
}
Above code to
// Get Postspublicfunctionread() {
// Create query$query = 'SELECT c.name as category_name, p.id, p.category_id, p.title, p.body, p.author, p.created_at FROM ' . $this->table . ' p LEFT JOIN categories c ON p.category_id = c.id ORDER BY p.created_at DESC';
// Prepare statement$stmt = $this->conn->prepare($query);
// Execute query$stmt->execute();
return$stmt->fetchAll(PDO::FETCH_ASSOC);
}
Why can't we get fetch all data form table and just return that data, then in while reading data just pass that data into to
json_encode
something like this?In
models/Post.php
Above code to
Then in
api/post/read.php
So that we can cut short the coding right..
The text was updated successfully, but these errors were encountered: