【发布时间】:2014-03-08 13:20:14
【问题描述】:
我们接到了一个学校项目,但我不知道该怎么做。 所以问题是我们要为企业建立一个数据库;我们是一家美容院。 我现在的问题是如何在表格中显示查询中的数据。
我看过以前的帖子,这似乎是一个答案,但我不知道它对我的情况真的有效
stackoverflow question: group query results in php
所以我在这里有当前结果和我希望它看起来如何的要点。基本上我希望员工姓名跨越多行等于他们提供的服务数量。
这是我目前的代码:
<?php
if (isset($_POST['submit']) && $error == '') {
echo "<table width='auto' border='1' class='center'>
<tr>
<th scope='col'>Transaction No.</th>
<th scope='col'>Service Name</th>
<th scope='col'>Employee Name</th>
<th scope='col'>Date</th>
<th scope='col'>Adjusted Price </th>
<th scope='col'>Adjusted Cost </th>
<th scope='col'>Adjusted Parlor Dividend</th>
<th scope='col'>Adjusted Employee Dividend</th>
</tr>";
$res=mysqli_query($con, "SELECT serviceline.transnum, servicelist.srvnam, employeelist.empname, serviceline.transdate, serviceline.priceadj, serviceline.costadj, serviceline.pardivadj, servicelist.price, serviceline.empdivadj, servicelist.cost, servicelist.pardiv, servicelist.empdiv FROM EmployeeList INNER JOIN (ServiceList INNER JOIN ServiceLine ON ServiceList.SrvID = ServiceLine.SrvID) ON EmployeeList.EmpID = ServiceLine.EmpID WHERE DATE(serviceline.transdate) BETWEEN '".$fyear."-".$fmon."-01' AND '".$tyear."-".$tmon."-31'");
while($ent=mysqli_fetch_array($res))
{
$adjprc=$ent['priceadj']+$ent['price'];
$adjcst=$ent['costadj']+$ent['cost'];
$adjpardiv=$ent['pardivadj']+$ent['pardiv'];
$adjempdiv=$ent['empdivadj']+$ent['empdiv'];
echo "<tr>
<th scope='row' e>".$ent['transnum']."</th>
<td>".$ent['srvnam']."</td>
<td>".$ent['empname']."</td>
<td>".$ent['transdate']."</td>
<td>Php ".number_format($adjprc, 2, '.', '')."</td>
<td>Php ".number_format($adjcst, 2, '.', '')."</td>
<td>Php ".number_format($adjpardiv, 2, '.', '')."</td>
<td>Php ".number_format($adjempdiv, 2, '.', '')."</td>
</tr>
";}
echo "</table>";
}
mysqli_close($con);
?>
提前致谢。
【问题讨论】:
-
您应该(并且作为一个好习惯)使用 ORDER BY 子句对查询结果进行排序,确保您的数据始终如一地返回到您的 PHP 页面。对于这个问题,您需要先按名称排序,然后按他们的服务排序。
标签: php html mysql sql database