Ahsan Ahsan - 5 months ago 18
PHP Question

Retrieving multiple queries from mysql using WHILE,&&Operator (NOT USING JOIN)

First of all i dont want to use JOIN
what am doing is fetching multiple queries through MySqli_Fetch_array(), The problem here is that because of the AND OPERATOR if any one of the MySqli_Fetch_array() is completed it stops all other and gives incomplete result of other tables. If am putting OR operator thats also not appropriate because if the first condition gives true it wont execute other.

This is my generalized code for you people to understand

while (($ans4=mysqli_fetch_array($result4))&&($ans5=mysqli_fetch_array($result5))&&($ans3=mysqli_fetch_array($result3))&&($ans1= mysqli_fetch_array($result1))&&($ans2=mysqli_fetch_array($result2))) {

echo "<tr>";

echo " <td>".$ans1['name']."</td> ";
echo " <td>".$ans2['id']."</td> ";
echo " <td>".$ans3['company']."</td> ";
echo " <td>".$ans4['owner']."</td> ";
echo " <td>".$ans5['Oid']."</td> ";

echo "</tr>";



Your way of doing queries is certainly not optimal since you could certainly achieve what you want doing less queries or altering your database design.You do 5 queries in order to get 5 fields that seem to be related.....

That beign said you could try using bitwise OR operator $a | $b to avoid short circuit evaluation.

while (($ans4=mysqli_fetch_array($result4)) |($ans5=mysqli_fetch_array($result5)) | ($ans3=mysqli_fetch_array($result3)) | ($ans1= mysqli_fetch_array($result1))|($ans2=mysqli_fetch_array($result2))) {