Having issues with putting a select statement to a Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mym8cat
Forum Newbie
Posts: 3
Joined: Thu Jul 03, 2003 6:16 am

Having issues with putting a select statement to a Variable

Post by mym8cat »

I am a newbie to PHP, long time lurker, first-time poster.

I have a Query that I would like to modify the Date/Time format in the presentation, however when I use date_format, my query goes pearshaped.

working:-
$result = mysql_query("SELECT opposition, id, venue, team, level, points_for, points_against, triescons, pens, drop_g, result, report, pictures from fixtures where team =1");

This is then placed into a table for viewing.

However, when I try:-
$result = mysql_query("SELECT date_format(date'%b %D, %Y -- @ %T hrs'), opposition, id, venue, team, level, points_for, points_against, triescons, pens, drop_g, result, report, pictures from fixtures where team =1");

It doesn't work. I think it is an issue with the Brackets within Brackets, but just guessing here. The query works fine as a cmd line but not with PHP.
Sorry if this is below you guys, but I'm stuck :(
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need to add a comma between the date field name and the formatting options in the date_format() bit, so:

Code: Select all

DATE_FORMAT(date, '%b %D, %Y -- @ %T hrs')
instead of

Code: Select all

DATE_FORMAT(date'%b %D, %Y -- @ %T hrs')
Mac
mym8cat
Forum Newbie
Posts: 3
Joined: Thu Jul 03, 2003 6:16 am

Post by mym8cat »

Sorry, fat-finger error in original request, I do have the comma, still seem to have issues.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What error message do you get if you add a bit of error handling:

Code: Select all

$sql = "SELECT DATE_FORMAT(date, '%b %D, %Y -- @ %T hrs'), opposition, id, venue, team, level, points_for, points_against, triescons, pens, drop_g, result, report, pictures FROM fixtures WHERE team = 1";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Mac
mym8cat
Forum Newbie
Posts: 3
Joined: Thu Jul 03, 2003 6:16 am

Post by mym8cat »

Cheers Mac, that's cracked it.... no error just the business!!
Thanks a lot!
:lol:
Post Reply