I am trying to fetch some data and show it to on a table. I am using two query for this. $result = Query1
and $result2 = Query2
. I am looping the $result to show it on the table which is working fine. However, when I am looping $result2
inside $result
I am getting only data for one row but not for the other rows. I have checked $result2
and it has all the data needed for the purpose. Bellow is the code I am using.
<?php
$query="SELECT client_order.id,client_order.total, client_order.date_of_order, client.firstname, client.lastname, client.address, client.city, client.zipcode, client.phone, client.email FROM `client_order` JOIN `client` ON client_order.id=client.Id WHERE client_order.date_of_order BETWEEN '".$todaysDate."' AND '".$tomorrowsDate."'";
$query2="SELECT * FROM `order_item` WHERE `OrderDate` BETWEEN '".$todaysDate."' AND '".$tomorrowsDate."'";
$result=mysqli_query($link,$query);
$result2=mysqli_query($link,$query2);
f(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
?>
<tbody>
<tr class="clickable" data-toggle="collapse" data-target=".rowCollapsed">
<td>
<?php echo $row["id"]?>
</td>
<td>
<?php echo $row["firstname"]." ".$row["lastname"]?>
</td>
<td>
<?php echo $row["address"]?>
</td>
<td></td>
<td>
<?php echo $row["Quantity"]?>
</td>
<td>
<?php echo $row["total"]?>
</td>
<td>
<?php echo $row["date_of_order"]?>
</td>
</tr>
<tr>
<th></th>
<th>Product Name</th>
<th>Size</th>
<th>Quantity</th>
<th>SubTotal</th>
<th></th>
<th></th>
</tr>
<?php
if(mysqli_num_rows($result2)> 0){
while($row2 = mysqli_fetch_array($result2)){
if($row2["order_id"]==$row["id"]){
?>
<tr>
<td></td>
<td>
<?php echo $row2["Product_Name"]?>
</td>
<td>
<?php echo $row2["Size"]?>
</td>
<td>
<?php echo $row2["Quantity"]?>
</td>
<td>
<?php echo $row2["SubTotal"]?>
</td>
<td></td>
<td></td>
</tr>
<?php
}
}
}
?>
</tbody>
<?php
}
}
I seem to get same value for $row["id"]
in every loop of the inner while loop. Can't figure out why this is happening. Where am I doing wrong here?