defroster Posted August 26, 2010 Share Posted August 26, 2010 A bit troubled, any input would be much appreciated This works fine: $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE videos.cat_id =" . $_GET['cat'] . " AND videos.status ='1'"; And this doesn't.. Any ideas why? What am I doing wrong. $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE videos.cat_id =" . $_GET['cat'] . " AND videos.status ='1' AND videos.dateposted <= now()"; Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2010 Share Posted August 26, 2010 It would really help if you told us what it did do - a) Produced a sql error? b) Executed without error but matched zero rows? c) Returned the wrong rows? Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104160 Share on other sites More sharing options...
defroster Posted August 26, 2010 Author Share Posted August 26, 2010 Thanks for quick reply. I get this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/cat.php on line 247 Line 247 $total_pages = mysql_fetch_array(mysql_query($query)); A bit of all the code: $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE videos.cat_id =" . $_GET['cat'] . " AND videos.status ='1' AND videos.dateposted <= now()"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104161 Share on other sites More sharing options...
shlumph Posted August 26, 2010 Share Posted August 26, 2010 Is the only difference the fact you appended videos.dateposted <= now() to your query? There's obviously a problem there then, and after answering PFMaBiSmAd, you should find the problem mightily quick Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104163 Share on other sites More sharing options...
shlumph Posted August 26, 2010 Share Posted August 26, 2010 What does mysql_query($query) or die(mysql_error()) return? Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104164 Share on other sites More sharing options...
defroster Posted August 26, 2010 Author Share Posted August 26, 2010 Sorry guys, it was me. I had a faulty code on another place returning an invalid id. Time for bed I guess Thanks for the help anyways. Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104166 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2010 Share Posted August 26, 2010 You MUST ALWAYS validate external data. If $_GET['cat'] didn't have a value in it or it was not numeric, you should have never executed the query. Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104167 Share on other sites More sharing options...
defroster Posted August 26, 2010 Author Share Posted August 26, 2010 You are absolutely correct PFMaBiSmAd. I see your signature says the same: Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect. Thanks and good night, df Link to comment https://forums.phpfreaks.com/topic/211832-query-problem-most-likely-simple/#findComment-1104171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.