예제 #1
0
파일: hello.php 프로젝트: Wainaina3/pos
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
}