Home > Enterprise >  how can I get multiple query responses in php?
how can I get multiple query responses in php?

Time:11-22

Hello everyone and thanks for reading. I'm using php to receive some queries in an android app, but I only know how to receive only one object from an array, I don't know how to receive the entire array. This is what I have done in my php document. enter image description here

CodePudding user response:

You are just getting the first result. You need to iterate over all results.

$result = mysqli_query($conn, $query);
while (($res = mysqli_fetch_assoc($result))) {
    // Do jour job with $res
}

Note: Also, I've changed mysqli_fetch_array with mysqli_fetch_assoc, as you only will treat $res as an associative array.

CodePudding user response:

In your case $res is array, so you need iterate over it to get acceess to rows from dtabase. For example:

$res = mysqli_fetch_array();
foreach($res as $row){
 $columnValue =  $row['columnName'];
}

So you need to do the same as presented in code sample as you need.

  • Related