Query stop working after change Where for Where in ()
Hi i used a COunt(*) to paginate in my php code,
The Variable $cat , look like this sometimes is
$cat = (1,2,3,4)
$cat = (1)
This time i need multiple cats, thats why thanks sorry for missing that ,
I always use something like
$query = "SELECT COUNT(*) as num FROM $tableName WHERE cat_id=$cat";
$total_pages = mysql_fetch_array(mysql_query($query)or
trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR));
$total_pages = $total_pages['num'];
But now i nee to use WHERE id IN (1,2,3,4,5,etc) this is the actual query..
$query = "SELECT COUNT(*) as num FROM $tableName WHERE cat_id IN ($cat)";
$total_pages = mysql_fetch_array(mysql_query($query)or
trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR));
$total_pages = $total_pages['num'];
But i get this error using WHERE IN
Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in /Applications/MAMP/htdocs/pcweb/admin/tiendas.php on
line 173
So how do you di this count then.. thanks i think there must be an easy
syntax error, but i cant find it cause i have never used Where IN, i look
into documentation here. http://www.w3schools.com/sql/sql_in.asp but i
think i do not know exactly what to google, so i ask..
Thanks
No comments:
Post a Comment