WHERE problems..

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

WHERE problems..

Post 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?
Image Image
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

use: WHERE to = 'news'
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

where are the fields 'to' and 'news' from?
edit: I AM too slow ;)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try

'to' = 'news'
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I try 'to' = 'news' and it runs, but nothing shows up. I'm guessing it's looking for 'news' and not news.
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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.
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

okay try

`to` = 'news'


cause, i think "TO" might be a MySQL command, and thats why its spitting out parse errors
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply