PHP MYSQL SET在while循环中给出错误 [英] PHP MYSQL SET gives error in while loop

查看:84
本文介绍了PHP MYSQL SET在while循环中给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询:

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

while ($rowb = mysql_fetch_array($result2)) {
//DO STUFF
}

但是SET @ total = 0;使while行给我一个错误: 警告:mysql_fetch_array():提供的参数在以下位置不是有效的MySQL结果资源 该查询在phpmyadmin中运行良好,而在没有SET @ total = 0的情况下运行良好;

But the SET @total=0; makes the while line give me an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in The query works fine in phpmyadmin and the while works fine without the SET @total=0;

推荐答案

由于在mysql_query()中不能使用多个查询,但是您可以将两个查询合并为一个查询.

As you can not use more than one queries in mysql_query(), But you can combine both your query into a single one.

尝试此查询.

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

这篇关于PHP MYSQL SET在while循环中给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆