The console displays only the first result of server api from mysql

hello ,
iwanted to get the result of this query to display all the results in my ionic 3 application but it returns only the first
row .
<php

$item=array();
$q = mysqli_query($con," SELECT * FROM reclamation WHERE cin_cit = ‘$postjson[cin]’ ");

while( $r=mysqli_fetch_array($q) )
{

$item = array (
‘rec_id’ => $q[‘rec_id’],
‘type_rec’ => $q[‘type_rec’],
‘description’ => $q[‘sujet’],
‘adresse’ => $q[‘adresse’],
‘laptitude’ => $q[‘laptitude’],
‘longitude’ => $q[‘longitude’],
‘etat_rec’ => $q[‘etat_reclamation’],
‘datetime’ => $q[‘datetime’],
‘gouvernorat’ => $q[‘nom_gouv’],
‘commune’ => $q[‘nom_com’],
‘cin_admin’ => $q[‘cin_admin’],
‘postal’ => $q[‘postal’],
‘fichiers’ => $q[‘justification’]
);

}

$result = json_encode(array(‘items’=>$item));
echo$result;

?>

unable to solve this ,help pls , how to put all rows in this array to send it to my ionic 3 application?

Do you get all rows from you server in your JSON data?

1 Like

Hello yes , i wanted to get all the rows in json data
here the capture of server response Capture
as u see the array do not have all rows

Can you just print the MySQL query string and see if query is correctly formed or not?

1 Like

Capture

here the mysql query in php code
```
$item=array();
$q = mysqli_fetch_array(mysqli_query($con, " SELECT * FROM reclamation WHERE cin_cit = ‘$postjson[cin]’ "));

      $item[] = array (
        'rec_id' => $q['rec_id'],
        'type_rec' => $q['type_rec'],
        'description' => $q['sujet'],
        'adresse' => $q['adresse'],
        'laptitude' => $q['laptitude'],
        'longitude' => $q['longitude'],
        'etat_rec' => $q['etat_reclamation'],
        'datetime' => $q['datetime'],
        'gouvernorat' => $q['nom_gouv'],
        'commune' => $q['nom_com'],
        'cin_admin' => $q['cin_admin'],
        'postal' => $q['postal'],
        'fichiers' => $q['justification']
      );

      $result = json_encode(array('items'=>$item));
      echo $result;

No I am saying what is the query that gets formed? Print that query and see if there is any issue with the query.

this is the query that i will get it’s result in ionic
$q = mysqli_fetch_array(mysqli_query($con, " SELECT * FROM reclamation WHERE cin_cit = ‘$postjson[cin]’ "));

Can you just

echo  "SELECT * FROM reclamation WHERE cin_cit = '$postjson[cin]'";
exit();

on your server and tell me what you get?

Capture

it displays one result while there are more then one on data base

Ok, does it give you more than 1 result while executing the query in phpmyadmin?

1 Like

yes , that’s mean this query is wrong but i can not know what to add to make it correct