当值来自数据库时表未排序 [英] Table not sorting when the value is from the database
问题描述
我的问题是如果 table 的值来自数据库,则该表未排序.
My problem is if the value of table is from the database the table is not sorting.
$sql=("SELECT *,SUM(unit_cost*quantity) AS total_amount FROM procurement WHERE rfq LIKE '13-___' GROUP BY counter ORDER BY rfq");
$result=mysql_query($sql);
echo'<table id="tfhover" cellspacing="0" class="tablesorter">
<thead>
<tr>
<th title="RFQ"></th>
<th title="RFQ">RFQ #</th>
<th title="Item Name">Item Name</th>
<th title="Item Description">Description</th>
<th title="Example : Pc, Pcs, Box and Etc.">Unit</th>
<th title="Item Price">Unit Cost</th>
<th title="Total Item Quantity">QTY</th>
<th title="Total Price">Total Amount</th>
</tr>
</thead>';
while($row = mysql_fetch_array($result)){
echo' <tbody>
<tr>
<td align="center"><a href="comments.php?pn='.$row["rfq"].'"><img src="images/remarks.png" border="0" width="10" height="10" title="Remarks and Notes"></a></td>
<td>'.$row['rfq'].'</td>
<td>'.$row['item_name'].'</td>
<td>'.$row['item_description'].'</td>
<td>'.$row['unit'].'</td>
<td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
<td>'.$row['quantity'].'</td>
<td>'.number_format($row['total_amount'], 2, '.', ',').'</td></tr></tbody>';
}
echo "</table>";
?>
但是当 table 的值不是来自数据库时,它可以完美地工作.我应该怎么办?
But when the value of table does not came from the database it's works perfectly. What should I do?
<tr>
<th>Major</th>
<th>Gender</th>
<th>English</th>
<th>Japanese</th>
<th>Calculus</th>
<th>Geometry</th>
</tr>
</thead>
<tbody>
<tr>
<td>Student01</td>
<td>Languages</td>
<td>male</td>
<td></td>
<td>70</td>
<td></td>
</tr>
<tr>
<td>Student02</td>
<td>Mathematics</td>
<td>male</td>
<td>90</td>
<td>88</td>
<td></td>
</tr>
<tr>
<td>Student03</td>
<td>Languages</td>
<td>female</td>
<td>85</td>
<td>95</td>
<td>80</td>
</tr>
</tbody>
</table>
我从 http://tablesorter.com/docs/
推荐答案
将 Put the 试试这个代码, 这篇关于当值来自数据库时表未排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 置于
while
循环之外.
<tbody>
out of the while
loop.$sql=("SELECT *,SUM(unit_cost*quantity) AS total_amount FROM procurement WHERE rfq LIKE '13-___' GROUP BY counter ORDER BY rfq");
$result=mysql_query($sql);
echo'<table id="tfhover" cellspacing="0" class="tablesorter">
<thead>
<tr>
<th title="RFQ"></th>
<th title="RFQ">RFQ #</th>
<th title="Item Name">Item Name</th>
<th title="Item Description">Description</th>
<th title="Example : Pc, Pcs, Box and Etc.">Unit</th>
<th title="Item Price">Unit Cost</th>
<th title="Total Item Quantity">QTY</th>
<th title="Total Price">Total Amount</th>
</tr>
</thead>
<tbody>';
while($row = mysql_fetch_array($result)){
echo'<tr>
<td align="center"><a href="comments.php?pn='.$row["rfq"].'"><img src="images/remarks.png" border="0" width="10" height="10" title="Remarks and Notes"></a></td>
<td>'.$row['rfq'].'</td>
<td>'.$row['item_name'].'</td>
<td>'.$row['item_description'].'</td>
<td>'.$row['unit'].'</td>
<td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
<td>'.$row['quantity'].'</td>
<td>'.number_format($row['total_amount'], 2, '.', ',').'</td>
</tr>';
}
echo "</tbody></table>";
登录
关闭