1

我想要做的是在顶部显示最后一个条目的页面上显示收入。但它仍然需要将总数增加到每一行。

所以第一页可能看起来像这样:

Date      Amount    Balance
1/9/2013   10.00    80.00
1/7/2013   10.00    70.00
1/6/2013   10.00    60.00

第 2 页可能如下所示:

Date      Amount    Balance
1/5/2013   10.00    50.00
1/4/2013   10.00    40.00
1/3/2013   10.00    30.00
1/2/2013   10.00    20.00
1/1/2013   10.00    10.00

但这就是我得到的:

Date      Amount    Balance
1/9/2013   10.00    60.00
1/7/2013   10.00    70.00
1/6/2013   10.00    80.00

第 2 页如下所示:

Date      Amount    Balance
1/5/2013   10.00    10.00
1/4/2013   10.00    20.00
1/3/2013   10.00    30.00
1/2/2013   10.00    40.00
1/1/2013   10.00    50.00

请注意,天平是向后的。但即使我的示例没有显示,金额的顺序也是正确的。这是我的代码:

SELECT *,
@total:= @total+ `companyearned` AS `total`
FROM `recordedhours`, (SELECT @total:=0) r WHERE `group` = '$uid'
ORDER BY `unixdate` DESC, `idnum` DESC
LIMIT $from, $max_results

 while ($rowb = mysql_fetch_array($result2)) {
//CREATE ROWS HERE
}

非常感激你的帮助!:)

4

1 回答 1

0

尝试这个SQL

SELECT * FROM
(
    SELECT *, @total:= @total+ `companyearned` AS `total`
    FROM `recordedhours`, (SELECT @total:=0) r WHERE `group` = '$uid'
    ORDER BY `unixdate` ASC, `idnum` DESC
    LIMIT $from, $max_results
) tab ORDER BY `unixdate` DESC
于 2013-04-23T15:50:08.143 回答