0

Possible Duplicate:
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

 <? } ?>

That shows.. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource near

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

MYSQL VERSION is 5.2.3-falcon-alpha.

Community
  • 1
  • 1
paul y cho
  • 39
  • 1
  • 9
  • You are not doing any error checking in your query. See http://php.net/manual/en/function.mysql-query.php – Pekka Jun 14 '12 at 14:48
  • 1
    `mysql_error()` is your friend – John Conde Jun 14 '12 at 14:49
  • #1. mysql_* extensions are deprecated use `mysqli` or `PDO`.... #2. When I have a query that just won't work, I echo out the query itself -- then copy it into phpmyadmin and see what it has to tell me.... I often find my answer that way... but both the guys above are correct in that you really need to do some error checking. – Justin Jun 14 '12 at 14:52

2 Answers2

3

You are passing a string to mysql_fetch_array instead of MySQL resource. You need to do:

$res = mysql_query($result);

before

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

Then, if the $result query is correct, you should get results.

Zagor23
  • 1,953
  • 12
  • 14
2

You are doing mysql_fetch_array($result), but $result actually contains the text of your query:

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

Your actual result is lost, because you have had it stored in $row_object which then you overwrite with the result of mysql_fetch_object().

lanzz
  • 42,060
  • 10
  • 89
  • 98
  • Thanks Lanzz~ I solved with Zagor23. But the other problem is "$actual_row_count" output "0". Is there any problem near "select SQL_CALC_FOUND_ROWS a.*, ..." ? – paul y cho Jun 14 '12 at 15:38
  • You should probably post a new question about it, and post your current code. In the code posted in your question, you never execute the `SQL_CALC_FOUND_ROWS` query. – lanzz Jun 15 '12 at 18:33