• Home
  • Hosting
  • Search
  • Member List
  • Calendar
  • Help

 

Current time: 09-09-2010, 03:34 AM Hello There, Guest! (Login — Register)


Space Socket Community / Design and Development / Development / Databases (MySQL, SQLite, etc.) v
1 2 3 4 5 ... 21 Next »
/ Query Problem

100MB Hosting with Free Domain
Cpanel hosting & domain for $19.95/yr.
Cpanel Free Hosting Packages
upto 1GB space with PHP/ASP/Perl/Ruby & MySQL
1month free trail hosting
no payment for 1st month, choose any monthly or yearly plan afterwards

Thread Closed 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
| Threaded Mode | Linear Mode |
Query Problem
07-01-2009, 04:58 PM
Post: #1
North Offline
Administrator
*******
Posts: 715
Joined: Dec 2007
Reputation: 5
Query Problem
Anyone know what I'm doing wrong here:

Quote:SELECT * FROM messages WHERE to = 1 ORDER BY time DESC LIMIT 0, 20

That returns:

Quote: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 = 1 ORDER BY time DESC LIMIT 0, 20' at line 1

"time" is of type DATETIME. "to" is of type MEDIUMINT.

It works if I get rid of "WHERE to = 1" which I need (it's a PM system...you don't want everyone to read your PMs!). What do I do? Use subqueries? (not sure what I'd do for that) Thanks for any help given.

EDIT: I've also tried doing WHERE to = "1" but that doesn't work either.


All moderations in indigo.

http://www.caglow.com - The open astronomy force.
http://aciqra.caglow.com - Free desktop planetarium.
http://i.caglow.com - Scripting language.

~North to the future

Visit this user's website Find all posts by this user
07-02-2009, 10:04 AM
Post: #2
North Offline
Administrator
*******
Posts: 715
Joined: Dec 2007
Reputation: 5
RE: Query Problem
Figured out the problem...had to surround time with`` because TIME is a reserved word in MySQL.


All moderations in indigo.

http://www.caglow.com - The open astronomy force.
http://aciqra.caglow.com - Free desktop planetarium.
http://i.caglow.com - Scripting language.

~North to the future

Visit this user's website Find all posts by this user
09-19-2009, 01:31 AM
Post: #3
madeinqc Offline
Member
***
Posts: 82
Joined: Sep 2009
Reputation: 0
RE: Query Problem
yes was about to tell you, it's a good idea to surround each database/table names with ``, it'll avoid lot of errors
Find all posts by this user
09-19-2009, 02:47 AM
Post: #4
UHF Offline
Banned
Posts: 47
Joined: Sep 2009
RE: Query Problem
`` is mainly for tables or columns that might have bits that break, such as space _ or -, also the windows word ` is different to every other one so dont copy and paste, causes alot of peole issues like that
Find all posts by this user
12-14-2009, 04:42 AM
Post: #5
yyrobin Offline
Junior Member
**
Posts: 4
Joined: Dec 2009
Reputation: 0
RE: Query Problem
To should add ` both side:`To`
Find all posts by this user
12-15-2009, 03:29 AM
Post: #6
wertyuio Offline
Junior Member
**
Posts: 31
Joined: Sep 2008
Reputation: 0
RE: Query Problem
and selecting all (SELECT * FROM) is bad habbit, try only selecting stuff you need
Find all posts by this user
12-25-2009, 09:47 AM
Post: #7
annguyen Offline
Junior Member
**
Posts: 5
Joined: Dec 2009
Reputation: 0
RE: Query Problem
SELECT * FROM `messages` WHERE `to` = 1 ORDER BY `time` DESC LIMIT 0, 20
Find all posts by this user
05-22-2010, 03:14 PM
Post: #8
adsmail Offline
Junior Member
**
Posts: 4
Joined: May 2010
Reputation: 0
RE: Query Problem
or without ''
SELECT * FROM messages WHERE to = 1 ORDER BY time DESC LIMIT 0, 20
Find all posts by this user
« Next Oldest | Next Newest »
Thread Closed 


  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


Contact Us | Space Socket | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication

Powered By MyBB, © 2002-2010 MyBB Group.
CoolLime - Designed by MyBBThemes