I used to get data from db and display to a table inside (see image)
It display all the ordered data from the db to the (Item, Qty,Price,Total).
But i need only specific ordereditem filtered by orderno.
Whats wrong in below code?
Solve this issue and Thanks in advance.
Below is the php mysql method.
public function read() { $data = array(); $query = "SELECT DISTINCT `orderdate`,`orderno`,`waitername`,`tablename` FROM `entrysales` WHERE `billstatus`='unbilled' ORDER BY id DESC"; $execute = mysqli_query($this->conn,$query); while($row=mysqli_fetch_assoc($execute)) { $data[]=$row; //$orderno = $row['orderno']; } return $data; } public function readitems(){ $data1 = array(); echo $query = "SELECT DISTINCT `orderno` FROM `entrysales` WHERE `billstatus`='unbilled' ORDER BY id DESC"; $execute = mysqli_query($this->conn,$query); while($row=mysqli_fetch_assoc($execute)) { //$data[]=$row; $orderno = $row['orderno']; echo $query1 = "SELECT * FROM `entrysales` WHERE `orderno`='$orderno' ORDER BY id DESC"; $execute1 = mysqli_query($this->conn,$query1); while($row1=mysqli_fetch_assoc($execute1)) { $data1[] = $row1; } } return $data1; }
And below is the php html code
$output = ''; $data = $db2->read(); $data1 = $db2->readitems(); foreach ($data as $row) { $count++; $output .='<tr class="text-center text-secondary"> <td>'.$count.'</td> <td>'.$row['orderdate'].'</td> <td>'.$row['orderno'].'</td> <td>'.$row['waitername'].'</td> <td>'.$row['tablename'].'</td>'; $output .='<td><table class="table">'; foreach($data1 as $row1){ $output .='<tr><td>'.$row1['orderitem'].'</td> <td>'.$row1['orderqty'].'</td> <td>'.$row1['unitprice'].'</td> <td>'.$row1['orderprice'].'</td></tr>'; } $output .='</table></td>'; $output .='<td> <a href="" title="Edit details" class="text-primary editEntrySalesBtn" id="'.$row['orderno'].'" data-toggle="modal" data-target="#addTakeOrderModal"><i class="fas fa-edit fa-lg"></i></a> <a href="" title="Delete details" class="text-danger delEntrySalesBtn" id="'.$row['orderno'].'"><i class="fas fa-trash-alt fa-lg"></i></a> </td> </tr>'; } $output .='</tbody></table>'; echo $output;
Advertisement
Answer
i’ve changed readitems method like below to get desired output as i wanted. Thanks to the one who tried to help. m.finger to the downvoters!
public function readitems() { $output = ''; $output .='<table id="table8" class="table table-striped table-sm table-bordered"> <thead> <tr class="text-center"> <th>Sl.No</th> <th>Order Date</th> <th>Order No</th> <th>Waiter Name</th> <th>Table Name</th> <th> <table id="table9" class="table table-striped table-sm table-bordered"> <tr> <th>Item</th> <th>Qty</th> <th>Rate</th> <th>Total</th> </tr> </table> </th> <th>Action</th> </tr> </thead> <tbody>'; $count = 0; $query = "SELECT DISTINCT `orderno`,`orderdate`,`waitername`,`tablename` FROM `entrysales` WHERE `billstatus`='unbilled' ORDER BY `orderno` DESC"; $execute = mysqli_query($this->conn,$query); while($row3=mysqli_fetch_assoc($execute)) { echo $orderno = $row3['orderno']; $count++; $output .='<tr class="text-center text-secondary"> <td>'.$count.'</td> <td>'.$row3['orderdate'].'</td> <td>'.$row3['orderno'].'</td> <td>'.$row3['waitername'].'</td> <td>'.$row3['tablename'].'</td>'; $output .='<td><table class="table">'; echo $query1 = "SELECT * FROM `entrysales` WHERE `orderno`='$orderno' ORDER BY id DESC"; $execute1 = mysqli_query($this->conn,$query1); foreach($execute1 as $row) { $output .='<tr class="text-center text-secondary"> <td>'.$row['orderitem'].'</td> <td>'.$row['orderqty'].'</td> <td>'.$row['unitprice'].'</td> <td>'.$row['orderprice'].'</td> </tr>'; } $output .='</table></td>'; $output .='<td> <a href="" title="Edit details" class="text-primary editEntrySalesBtn" id="'.$row3['orderno'].'" data-toggle="modal" data-target="#addTakeOrderModal"><i class="fas fa-edit fa-lg"></i></a> <a href="" title="Delete details" class="text-danger delEntrySalesBtn" id="'.$row3['orderno'].'"><i class="fas fa-trash-alt fa-lg"></i></a> </td> </tr>'; } $output .='</tbody></table>'; return $output; }