RE: [PHP-DB] Newbie : URGENT : SELECT ... AS

From: Date: Sat, 14 Apr 2001 17:35:12 +0000
Subject: RE: [PHP-DB] Newbie : URGENT : SELECT ... AS
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-8567@lists.php.net to get a copy of this message
try using single quotes instead of double quotes: SELECT firstname, surname, dob, floor((to_days(curdate())-to_days(DOB))/365) AS age FROM artistes WHERE age = '25'; Francois Legare flegare@interchange.ubc.ca Vancouver BC Canada 604.261.1320 > -----Original Message----- > From: Matt Coyne [mailto:m@threezero.co.uk] > Sent: April 14, 2001 5:07 AM > To: PHP DB > Subject: [PHP-DB] Newbie : URGENT : SELECT ... AS > > > Hi all > > I am trying to make searches based on the age of a person. The db contains > only the Date of Birth. > > So... > > My first attempt was to try the following : > (this is all done in the command line on Win2000) > > SELECT firstname, surname, dob, > floor((to_days(curdate())-to_days(DOB))/365) > AS age FROM artistes; > > This works and returns all the values with the addition of an age column > with what appears to be the correct age. > > However... > > When I try adding a WHERE clause: > > SELECT firstname, surname, dob, > floor((to_days(curdate())-to_days(DOB))/365) > AS age FROM artistes WHERE age = "25"; > > I get ERROR 1054: Unknown column 'age' in 'where clause' > > How am I to use this 'virtual' age column in my searches? > > I want to be able to search on exact and age ranges plus display > the age in > the returned results. > > Any ideas/feedback truly welcome, I am 'under the cosh' to get this done > asap!!! (as usual) > > TIA > > matt > > > //t h r e e z e r o : : : > > the mill, millstone lane, leicester, le1 5jn > e : m@threezero.co.uk :: w : www.threezero.co.uk > t : 0116 225 0662 :: m : 07747 845690 > > : : : t h r e e z e r o// > > > > From: Paul Burney <burney@gseis.ucla.edu> > > Date: Wed, 11 Apr 2001 19:07:02 -0700 > > To: Mike Baerwolf <mike@wkla.com>, <php-db@lists.php.net> > > Subject: Re: [PHP-DB] select substring_index > > > > on 4/11/01 7:48 PM, Mike Baerwolf at mike@wkla.com wrote: > > > >> SELECT substring_index( body, ". ", 2) FROM news; > >> > >> This works great from the mysql client but when I try it using php with > >> this: > >> > >> $result = mysql_query("SELECT substring_index(body, "." ,2) FROM > >> news" > > > > The way you have this written, PHP is using the . for > concatenation. To fix > > the problem you need to alternate or escape the quotes, i.e. : > > > > $result = mysql_query("SELECT substring_index(body, \".\" ,2) FROM > > news" > > > > or > > > > $result = mysql_query('SELECT substring_index(body, "." ,2) FROM news' > > > > or > > > > $result = mysql_query("SELECT substring_index(body, '.' ,2) FROM news" > > > > Hope that helps, > > > > Paul Burney > > http://paulburney.com/ > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#8567) next »