我曾经从数据库获取数据并显示到里面的表(见图)它显示从数据库到(项目,数量,价格,总计)的所有有序数据。但我只需要按 orderno 过滤的特定有序项目。下面的代码有什么问题吗?
解决这个问题并提前致谢。
下面是php mysql的方法。
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;
}
下面是 php html 代码
$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>';
}
慕容3067478
繁星淼淼