good night, help with JSONArray and JSONObject

1

I have the following code in a PHP

$json=array();
    if(isset($_GET["address"])){
        $documento=$_GET["address"];
        $conexion = mysqli_connect($hostname_localhost,$username_localhost,$password_localhost,$database_localhost);
        $consulta="select subject, created from dit_ticket__cdata inner join dit_ticket on dit_ticket__cdata.ticket_id=dit_ticket.ticket_id inner join dit_user_email on dit_user_email.user_id=dit_ticket.user_id where dit_user_email.address='{$documento}'";
$resultado=mysqli_query($conexion,$consulta); 
if($registro=mysqli_fetch_row($resultado)){
        $result["subject"]=$registro[0];
        $result["created"]=$registro[1];
        $json['usuario'][]=$result;                   
        }
        mysqli_close($conexion);
        echo json_encode($json);

and in Android Studio I use it like this:

public void onResponse(JSONObject response) {
        JSONArray json=response.optJSONArray("usuario");
        JSONObject jsonObject=null;
        try {
            jsonObject=json.getJSONObject(0);
            System.out.println(" motivo "+jsonObject.optString("subject"));
            System.out.println(" creado "+jsonObject.optString("created"));

there it shows me the first record of the 3 registered but if I add this line to the PHP file

I no longer show any record that line I only use it to show me only 1 record help please

    
asked by cracklos angeles 24.11.2018 в 02:42
source

1 answer

0

If you add to your query:

and status_id =1 

and you do not get any value means that none of the values of your first query has status_id with value 1

If you use your previous query, you can limit to showing only one record using LIMIT .

  

LIMIT In MySQL, the LIMIT clause is used with the instruction   SELECT to restrict the number of rows in the set of   results The Limit Clause accepts one or two arguments that are   offset and count. The value of both parameters can be zero or integers   positive.

Example:

$consulta="select ........ where dit_user_email.address='{$documento}' LIMIT 1";
    
answered by 24.11.2018 / 04:13
source