daveh33 Posted October 28, 2007 Share Posted October 28, 2007 $query = mysql_query("SELECT * from messages WHERE roomid='$rid' & WHERE to='all'") or die (mysql_error()); This code isn't working for me - can anyone advise?? Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/ Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 SELECT * from messages WHERE roomid='$rid' && to='all'; Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379810 Share on other sites More sharing options...
daveh33 Posted October 28, 2007 Author Share Posted October 28, 2007 thanks but I get this error You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='all' Order by time' at line 1 the code is $query = mysql_query("SELECT * from messages WHERE roomid='$rid' && to='all' Order by time") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379812 Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 Time is a reserved word. Try... $query = mysql_query("SELECT * FROM messages WHERE roomid='$rid' && to='all' ORDER BY `time`") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379821 Share on other sites More sharing options...
daveh33 Posted October 28, 2007 Author Share Posted October 28, 2007 Ah ok thats new to me - but I still get the error You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='all' ORDER BY `time`' at line 1 there is 7 records in the mysql where the to field is all - I don't understand why it wont work Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379825 Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 Hmmm, funnily enough, to is a reserved word aswell. $query = mysql_query("SELECT * FROM messages WHERE roomid='$rid' && `to`='all' ORDER BY `time`") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379832 Share on other sites More sharing options...
daveh33 Posted October 28, 2007 Author Share Posted October 28, 2007 Ah - well at least I know that in future when naming my fields! That line works now, many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/75098-solved-php-mysql-query-how-do-i-set-to-clauses-on-where-function/#findComment-379836 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.