mardi 29 décembre 2015

need to echo one row in json encode

I have this php file and I want to echo one array that ticketnumber is located in it with json encode, in meaning I want to print only one array when isset POST the ticketnumber for this array, but I tried and every time I get error how to slove this problem in addition I used the loop (while) so is it correct for one array?

<?php
define('HOST', 'localhost');
define('USER', 'root');
define('PASS','');
define('DB', 'ala');

$con = mysqli_connect(HOST,USER,PASS,DB) or die ('unable to connect');


    if ($_SERVER ['REQUEST_METHOD']=='POST') {

        $ticketnumber = $_POST['ticketnumber'];

        $sql = " SELECT * FROM contact WHERE ticketnumber = '$ticketnumber' ";

        $res = mysqli_query($con, $sql);

         $result = array();

        while($get = mysqli_fetch_array($res))
        {
            array_push($result,array('ticketnumber' =>$get[0], 'subject' =>$get[1],'response' =>$get[2]));
        }
        if(isset($get)){
            echo json_encode(array("responseticket"=>$result));
        } else {
            echo " error";
        }

}

?>




Aucun commentaire:

Enregistrer un commentaire