I would like to get data from MySQL database in json format and then print it to a PHP page.
I try to use this script:
<?php
    $page = $_GET['page'];
    $start = 0;
    $limit = 5;
    require_once('dbConnect.php');
    $total = mysqli_num_rows(mysqli_query($con, "SELECT id from photos"));
    $page_limit = $total/$limit;
    if($page<=$page_limit){
        $start = ($page - 1) * $limit;
        $sql = "SELECT * from photos limit $start, $limit";
        $result = mysqli_query($con,$sql);
        $res = array();
        while($row = mysqli_fetch_array($result)){
            array_push($res, array(
                "location"=>$row['location'],
                "image"=>$row['image'])
                );
        }
        echo json_encode($res);
    }else{
            echo "over";
    }
Database connection is OK, but it gives "over" message. Table contains 1 record, which details should be listed in JSON format.
