Page 1 of 1

WHERE problems..

Posted: Thu Sep 26, 2002 8:30 pm
by phice
My syntax:
"SELECT * FROM table WHERE to = news ORDER BY id LIMIT 0,15"
isn't working. If I delete the "WHERE to = news", then it works exactly how it's supposed to.

Any ideas?

Posted: Thu Sep 26, 2002 8:34 pm
by mydimension
use: WHERE to = 'news'

Posted: Thu Sep 26, 2002 8:36 pm
by volka
where are the fields 'to' and 'news' from?
edit: I AM too slow ;)

Posted: Thu Sep 26, 2002 10:55 pm
by phice
mydimension wrote:use: WHERE to = 'news'
I tried that, and it returned the same problem.

MySQL Query

Code: Select all

$result1 = mysql_query("SELECT * FROM pphp_news WHERE to = 'news' ORDER BY id DESC LIMIT 0,15",$connection) or die(mysql_error());
MySQL Error

Code: Select all

You have an error in your SQL syntax near 'to = 'news' ORDER BY id DESC LIMIT 0,15' at line 1

Posted: Thu Sep 26, 2002 11:12 pm
by hob_goblin
try

'to' = 'news'

Posted: Thu Sep 26, 2002 11:19 pm
by phice
I try 'to' = 'news' and it runs, but nothing shows up. I'm guessing it's looking for 'news' and not news.

Posted: Thu Sep 26, 2002 11:22 pm
by phice
Alright.

I tried "SELECT * FROM pphp_news WHERE id = '1'", and it works.

I renamed the column 'to' to 'towho', and ran it like above, and it works perfectly. Very weird.

Posted: Thu Sep 26, 2002 11:23 pm
by hob_goblin
okay try

`to` = 'news'


cause, i think "TO" might be a MySQL command, and thats why its spitting out parse errors

Posted: Fri Sep 27, 2002 1:38 am
by twigletmac
Check this out:
http://www.mysql.com/doc/en/Reserved_words.html

to is a reserved word in MySQL and can't be used as a column name.


Mac