javascript - 当值来自数据库时表不排序

标签 javascript php mysql

我的问题是,如果表的值来自数据库,则表不会排序。

    $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>";
    ?>

但是当表的值不是来自数据库时,它可以正常工作。我应该怎么办?

        <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/ 获取了脚本

最佳答案

输入 <tbody>while循环。

试试这个代码,

$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>";

关于javascript - 当值来自数据库时表不排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018626/

相关文章:

javascript - HTML输入日期,响应选择的值?

javascript - Ember.js ember-data restadapter 无法加载 json

php - CodeIgniter 将一个列值设置为另一个现有列值而不进行选择

php - 使用 PHP 面向对象编程简单更新 MySQL

php - 在 PHP 中连接条件查询,同时尝试从多个表中获取行

mysql - 为什么设置中的顺序这么难?

python - 从Python sql查询中的总和计算百分比/分数

javascript - 过滤选择框时选择第一个值

javascript - 更改特定 Javascript 生成的 iframe 的 CSS 样式

php - 影响格式化和 JS 输出的嵌套跨度元素