I would like to have e single query to get column value without "while"... is possible? I have two table like this... Owners:
+----+-------+---------+
| id | names | surname |
+------------+---------+
| 1 | John | Red |
| 2 | Mark | Green |
| 3 | Frank | Yellow |
| ...| ... |... |
+------------+---------+
Animals
+----+--------+--------+
| id |idOwner | animal |
+-------------+--------+
| 1 | 1 | Cat |
| 2 | 2 | Bird |
| 3 | 1 | Dog |
| ...| ... |... |
+-------------+--------+
Now I have this code:
$query='SELECT * FROM Owners WHERE id=1';
$con=new mysqli($dbhostname, $dbusername, $dbpassword, $dbname);
$result=$con->query($query);
$arr=array();
while ($own = $result->fetch_array(MYSQLI_ASSOC)) {
$qry='SELECT animal FROM Animals WHERE idOwner=own["id"]';
$rslt=$con->query($qry);
$i=1;
while ($aml = $rslt->fetch_array(MYSQLI_ASSOC)) {
$txt='animal'.$i;
$own['animal'.$i]=$aml['animal'];
$i++;
}
$arr[]=$own;
}
$con->close();
I would like to have the same result but with a single query because now the process is too late... is possible?