Пример #1
0
function getProdsByManufacs()
{
    if (!isset($_REQUEST['manf'])) {
        //return error
        echo '{"result":0,"message": "search did not work."}';
    }
    $search_text = $_REQUEST['manf'];
    include "products.php";
    $obj = new products();
    if (!$obj->searchByManfs($search_text)) {
        //return error
        echo '{"result":0,"message": "search did not work."}';
        return;
    }
    //at this point the search has been successful.
    //generate the JSON message to echo to the browser
    $row = $obj->fetch();
    echo '{"result":1,"products":[';
    //start of json object
    while ($row) {
        echo json_encode($row);
        //convert the result array to json object
        $row = $obj->fetch();
        if ($row) {
            echo ",";
            //if there are more rows, add comma
        }
    }
    echo "]}";
    //end of json array and object
}