2012-06-14 37 views
0

可能重複:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result我的sql查詢出了什麼問題?

<? 
$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():提供的參數不是近

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

一個有效的MySQL結果資源MYSQL VERSION是5.2.3-falcon-alpha。

+0

您在查詢中沒有執行任何錯誤檢查。見http://php.net/manual/en/function.mysql-query.php –

+1

'mysql_error()'是你的朋友 –

+0

#1。 mysql_ *擴展名已被棄用,使用'mysqli'或'PDO' .... #2。當我有一個查詢不起作用時,我會回覆查詢本身 - 然後將其複製到phpmyadmin中,並查看它告訴我的內容....我經常以這種方式找到我的答案......但是,上面的人是正確的,你真的需要做一些錯誤檢查。 – Justin

回答

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()

+0

謝謝Lanzz〜我用Zagor23解決了。但另一個問題是「$ actual_row_count」輸出「0」。 「select SQL_CALC_FOUND_ROWS a。*,...」附近有沒有問題? –

+0

你應該發佈一個關於它的新問題,併發布你的當前代碼。在你的問題發佈的代碼中,你永遠不會執行'SQL_CALC_FOUND_ROWS'查詢。 – lanzz

3

你傳遞一個字符串mysql_fetch_array,而不是MySQL的資源。 你需要做的:

$res = mysql_query($result); 

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

然後,如果$result查詢是正確的,你應該得到的結果。

+0

謝謝。有用。 ^^ –