how to filter data with json and php


I need someone to help me, I have a structure that receives data from a mysql database, I would like to show the data in the app but filtering the data that matches a variable I defined when loading the app, I have the following structure :

func datos3(){

        let url = URL(string: "http://test/test.php")

        Alamofire.request(url!).responseJSON { (response) in

            let result =
            do {
                self.filtro = try JSONDecoder().decode([ClientDADES].self, from: result!)
                DispatchQueue.main.async {
            } catch {
                print("Error al conectar php", error)


and in php:


    $servername = "test";
    $database = "test";
    $username = "test";
    $password = "test";

    $conn = mysqli_connect($servername, $username, $password, $database);

    $conn-> set_charset('utf-8');

        $resultado = array();
        $temporal= array();

        $conn->query("SET NAMES UTF8");

    $sel = $conn ->query("SELECT * FROM 'Cli'");

    while ($f = $sel->fetch_assoc()) {
       $temporal = $f;

       // $temporal = $f;
        array_push($resultado, $temporal);

    echo json_encode($resultado);


asked by Miquel Molina 20.12.2018 в 14:36

0 answers