0

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\me.php on line 30

$sql = mysql_query('SELECT * FROM cms_alert limit WHERE user_id = '.$user->row['id'].', 10');
while($row = mysql_fetch_assoc($sql)){

Does someone know what's te problem?

5 Answers5

0

You wrongly added the keyword limit before where

Try this

$sql = mysql_query('SELECT * FROM cms_alert WHERE user_id = '.$user->row['id'].' LIMIT 10');
Vijayaragavendran
  • 726
  • 1
  • 10
  • 21
0

Try using this -

$sql = mysql_query('SELECT * FROM cms_alert WHERE user_id = '.$user->row['id'].' limit 0,10');
TBI
  • 2,681
  • 1
  • 16
  • 21
  • Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\me.php on line 29 Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\me.php on line 30 – Generator Jul 19 '14 at 07:24
  • @Generator The answer does not use `mysqli_query`, but your error message does. You cannot mix mysql_ calls with mysqli_ calls. – Joachim Isaksson Jul 19 '14 at 07:36
  • Have you tried the query in your table directly ? Use static userid and run it once. – TBI Jul 19 '14 at 07:36
0

Please see the syntax for SELECT;

In your case you need to write LIMIT after your WHERE condition.

H. Mahida
  • 2,326
  • 1
  • 11
  • 23
0

if you are using php5.5 then mysql_fetch_assoc is deprecated see here

you can use mysqli driver

and make you query in double quotation single quotation is for varchar

 mysql_query("SELECT * FROM cms_alert WHERE user_id = '".$user->row['id']."' limit 0,10);
Muhammad Ali
  • 1,974
  • 1
  • 13
  • 19
  • Yes I did that. I also tried to add it after WHERE but I get the error Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\me.php on line 30 – Generator Jul 19 '14 at 07:28
  • make you query between double quotation – Muhammad Ali Jul 19 '14 at 07:31
0

You are using invalid SQL Query it should be

SELECT * FROM table_name WHERE id=some_id LIMIT 0, 20
Shushant
  • 1,617
  • 1
  • 13
  • 23