我的SQL查询有什么问题?

时间:2012-06-14 14:47:22

标签: mysql

  

可能重复:
  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

<?
 $result ="select SQL_CALC_FOUND_ROWS a.*, b.name as brandname ,(case when max(length(d.pcode)) >0  then 1  else 0 end) as eventflag,  min(d.price) as eventprice 
from brand b , product a left join event_product d on a.pcode = d.pcode where a.status != 0 and a.hotflag = 0 and a.bcode = b.code and  a.bcode = '$bcode'
group by a.pcode, a.bcode, a.ocode, a.ccode, a.pname, a.copy, a.etc, a.company, a.origin, a.status, a.opt1name, a.opt1value, a.opt2name, a.opt2value, a.opt3name, a.opt3value, a.gift_name, a.gift_file, a.gift_s_file, a.saleprice, a.saleflag, a.hotflag, a.hotcode, a.hotprice, a.price, a.term, a.point, a.pointflag, a.pointorder, a.content, a.html_check, a.couple1, a.couple2, a.couple3, a.regdate, a.cnt, a.sort, a.delflag, b.name   
order by a.regdate desc limit 12"; 

  $row_object = mysql_query("Select Found_Rows() as rowcount");
  $row_object = mysql_fetch_object($row_object);
  $actual_row_count = $row_object->rowcount;

?>

 SOME HTML 

 <? while ($row = mysql_fetch_array($result)) { ?>

 HTML OUTPUT

 <? } ?>

那显示..警告:mysql_fetch_array():提供的参数不是有效的MySQL结果资源

 <? while ($row = mysql_fetch_array($result)) { ?>

MYSQL VERSION是5.2.3-falcon-alpha。

2 个答案:

答案 0 :(得分:3)

您正在将字符串传递给mysql_fetch_array而不是MySQL资源。 你需要这样做:

$res = mysql_query($result);

<? while ($row = mysql_fetch_array($res)) { ?>

然后,如果$result查询正确,您应该得到结果。

答案 1 :(得分:2)

您正在执行mysql_fetch_array($result),但$result实际上包含查询的文本

$result ="select SQL_CALC_FOUND_ROWS a.*, b.name as brandname ,(case when max(length(d.pcode)) >0  then 1  else 0 end) as eventflag,  min(d.price) as eventprice 
from brand b , product a left join event_product d on a.pcode = d.pcode where a.status != 0 and a.hotflag = 0 and a.bcode = b.code and  a.bcode = '$bcode'
group by a.pcode, a.bcode, a.ocode, a.ccode, a.pname, a.copy, a.etc, a.company, a.origin, a.status, a.opt1name, a.opt1value, a.opt2name, a.opt2value, a.opt3name, a.opt3value, a.gift_name, a.gift_file, a.gift_s_file, a.saleprice, a.saleflag, a.hotflag, a.hotcode, a.hotprice, a.price, a.term, a.point, a.pointflag, a.pointorder, a.content, a.html_check, a.couple1, a.couple2, a.couple3, a.regdate, a.cnt, a.sort, a.delflag, b.name   
order by a.regdate desc limit 12"; 

您的实际结果会丢失,因为您已将其存储在$row_object中,然后使用mysql_fetch_object()的结果进行覆盖。