Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once './DbConnect.php';
- function getCategories(){
- $db = new DbConnect();
- $tmp = array();
- // array for json response
- $response = array();
- $response["categories"] = array();
- // Mysql select query
- $result = mysql_query("SELECT * FROM categories");
- while($row = mysql_fetch_array($result)){
- // temporary array to create single category
- $tmp["id"] = $row["id"];
- $tmp["name"] = $row["name"];
- // push category to final json array
- $response = array_push($response["categories"], $tmp);
- }
- // keeping response header to json
- header('Content-Type: application/json');
- // echoing json result
- echo json_encode($response);
- }
- getCategories();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement