Justtechjobs.com Find a programming school near you






Online Campus Both


php-db | 2001041

[PHP-DB] Newbie : URGENT : SELECT ... AS From: Matt Coyne (m <email protected>)
Date: 04/14/01

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 <email protected> :: 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 <email protected>>
> Date: Wed, 11 Apr 2001 19:07:02 -0700
> To: Mike Baerwolf <mike <email protected>>, <php-db <email protected>>
> Subject: Re: [PHP-DB] select substring_index
>
> on 4/11/01 7:48 PM, Mike Baerwolf at mike <email protected> 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 <email protected>
> For additional commands, e-mail: php-db-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>