Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Headers
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: application/json');
- include_once '../../config/Database.php';
- include_once '../../models/Forum.php';
- // Instantiate DB & connect
- $database = new Database();
- $db = $database->connect();
- // Instantiate forum object
- $forum = new Forum($db);
- // forum read query
- $result = $forum->read();
- // Get row count
- $num = $result->rowCount();
- // Check if any forum
- if($num > 0) {
- // forum array
- $pla_arr = array();
- $pla_arr['data'] = array();
- while($row = $result->fetch(PDO::FETCH_ASSOC)) {
- extract($row);
- $pla_item = array(
- 'id' => $id,
- 'nickname' => $plant_name,
- 'title' => $plant_type,
- 'description' => $details
- );
- // Push to "data"
- array_push($pla_arr['data'], $pla_item);
- }
- // Turn to JSON & output
- echo json_encode($pla_arr);
- } else {
- // No forum
- echo json_encode(
- array('message' => 'No forum Found')
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement