Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Programming & Software Development

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 10th January 2008, 6:15 PM   #1
DJel Thread Starter
Member
 
DJel's Avatar
 
Join Date: Sep 2006
Location: Sydney
Posts: 275
Default SQL Query [RESOLVED]

Hello,

I am trying to construct a SQL query for a MySQL database that selects certain fields but at the same time converts a datetime field into something more user friendly.

So far I have this query that selects and converts the date;
Code:
SELECT DATE_format(time_sent, '%M %e, %Y<br>%l:%i%p') as newdate FROM messages
Which outputs a date in a form like so; January 9, 2008 2:27PM (with a line break between the date and time)

And this query which selects all the other information I want;
Code:
SELECT from_username, subject, read, FROM messages WHERE to_username='$session->username'
I have tried to incorporate the formatting query (DATE_format(time_sent, '%M %e, %Y<br>%l:%i%p') as newdate) straight into the normal query like so;
Code:
SELECT DATE_format(time_sent, '%M %e, %Y<br>%l:%i%p') as newdate, from_username, subject, read, FROM messages WHERE to_username='$session->username']
as well as assigning it as a variable then inputting it. When I do this nothing is output. I am using PHP as my scripting language and the error message I receive is;
Quote:
SQL query:

SELECT DATE_format( time_sent, '%M %e, %Y<br>%l:%i%p' ) AS formatted_date, from_username, subject,
READ ,
FROM messages
WHERE to_username = 'username'
LIMIT 0 , 30

MySQL said:
#1064 - 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 'read , FROM messages WHERE to_username = 'username'
LIMIT 0, 30' at line 1
Any help would be greatly appreciated,

DJel.

Last edited by DJel; 10th January 2008 at 10:49 PM.
DJel is offline   Reply With Quote

Join OCAU to remove this ad!
Old 10th January 2008, 9:31 PM   #2
Elyzion
Member
 
Elyzion's Avatar
 
Join Date: Oct 2004
Location: Singapore
Posts: 6,256
Default

Why don't you just select it then format it in PHP.. It would be much easier.
__________________
Quote:
Originally Posted by SyN View Post
next time you see a dog, go up close to it and say loudly with furious anger 'ENGLISH MOTHERFUCKER, DO YOU SPEAK IT'
Elyzion is offline   Reply With Quote
Old 10th January 2008, 9:57 PM   #3
PhuckNut
Member
 
PhuckNut's Avatar
 
Join Date: Sep 2003
Posts: 547
Default

get rid of the , before the FROM
PhuckNut is offline   Reply With Quote
Old 10th January 2008, 10:48 PM   #4
DJel Thread Starter
Member
 
DJel's Avatar
 
Join Date: Sep 2006
Location: Sydney
Posts: 275
Default

Quote:
Originally Posted by Elyzion View Post
Why don't you just select it then format it in PHP.. It would be much easier.
By just incorporating it into the query I can avoid pointless code, at the moment there is a fair bit of code so if I can find ways to reduce the amount of code the better.

Quote:
Originally Posted by PhuckNut View Post
get rid of the , before the FROM
Thanks for that, the comma was one problem and there was also another problem with some quote marks further on.

Thanks for the help guys,

DJel.
DJel is offline   Reply With Quote
Old 11th January 2008, 7:42 AM   #5
houseofzeus
Member
 
Join Date: Mar 2005
Location: St. Lucia, Brisbane
Posts: 3,200
Default

Quote:
Originally Posted by DJel View Post
By just incorporating it into the query I can avoid pointless code, at the moment there is a fair bit of code so if I can find ways to reduce the amount of code the better.
Maybe, I'd argue it makes it less portable if you ever decide to switch dbms down the track.
houseofzeus is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 6:13 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!