borabora12 Posted December 13, 2008 Share Posted December 13, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource $queryconpos = mysql_query("SELECT @count := 0; SELECT @count := IF(dailydiff < 0, @count + 1, 0) as cntpos FROM the_table ORDER BY cntpos DESC LIMIT 1"); $resultconpos = mysql_fetch_array($queryconpos, MYSQL_BOTH); $conupdays = $resultconpos['cntpos']; echo "&conupdays=$conupdays"; what am I doing wrong here that I am getting an error? I tried inputing the following code in SQL sytex and it works: SELECT @count := 0; SELECT @count := IF(dailydiff < 0, @count + 1, 0) as cntpos FROM the_table ORDER BY cntpos DESC LIMIT 1 I get an output of cntpos 4 Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/ Share on other sites More sharing options...
corbin Posted December 14, 2008 Share Posted December 14, 2008 The select @count was just so I could rerun the query. It's causing an error because the mysql_query function only supports 1 query per call (security reasons). The @count := 0 is also necessary so it's not null. (NULL + x = NULL) So, you have two options: mysql_query("@count := 0;"); mysql_query(other query); Or: SELECT @count := IF(c < 0, IF(@count IS NULL, 1, @count + 1), 0) as cntpos FROM consec ORDER BY cntpos DESC LIMIT 1; (Or a CASE statement could be used. I would probably go with the first one, since the second one would add an extra IF call every row. Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/#findComment-715024 Share on other sites More sharing options...
borabora12 Posted December 14, 2008 Author Share Posted December 14, 2008 hey corbin so in other words it would be something like this: $query1 = mysql_query("SELECT @count := 0"); $query2 = mysql_query("SELECT @count := IF(dailydiff < 0, @count + 1, 0) as cntpos FROM the_table ORDER BY cntpos DESC LIMIT 1"); $result = mysql_fetch_array($query1, $query2); echo "$result['cntpos']" thanks again for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/#findComment-715190 Share on other sites More sharing options...
borabora12 Posted December 14, 2008 Author Share Posted December 14, 2008 Hey corbin I got it to work! Thanks for all the help man! Here is the solution just incase $query = mysql_query("SELECT @count := 0"); $query = mysql_query("SELECT @count := IF(dailydiff < 0, @count + 1, 0) as cntpos FROM the_table ORDER BY cntpos DESC LIMIT 1"); $result = mysql_fetch_array($query); echo "$result['cntpos']" Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/#findComment-715194 Share on other sites More sharing options...
corbin Posted December 14, 2008 Share Posted December 14, 2008 No problem. Glad it works. By the way, echo "$result['cntpos']"; Is redundant. You should just do echo $result['cntpos']; Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/#findComment-715310 Share on other sites More sharing options...
borabora12 Posted December 15, 2008 Author Share Posted December 15, 2008 thanks again corbin... you always come through Quote Link to comment https://forums.phpfreaks.com/topic/136870-solved-why-is-the-query-ending-up-blank/#findComment-715544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.