Page 1 of 1

Having issues with putting a select statement to a Variable

Posted: Thu Jul 03, 2003 6:16 am
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 :(

Posted: Thu Jul 03, 2003 6:48 am
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

Posted: Thu Jul 03, 2003 7:15 am
by mym8cat
Sorry, fat-finger error in original request, I do have the comma, still seem to have issues.

Posted: Thu Jul 03, 2003 7:23 am
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

Posted: Thu Jul 03, 2003 7:50 am
by mym8cat
Cheers Mac, that's cracked it.... no error just the business!!
Thanks a lot!
:lol: