Re: MySql and PHP question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From memory earlier versions of MySQL don't support subselects. The latest (and greatest) does so you may want to check the version you are using - I can't remember when it was introduced, I have since switched to PostGreSQL...

all the best,

graeme.

Juffermans, Jos wrote:

Hi,

I'm afraid I can't help you with the query - I'm used to Oracle which as a
bigger set of SQL commands.

I can help you with your PHP question. If you want to put a variable in a
query, you can add the variable directly into the string:
	$sql_query = "select zg_longitude from zip_code where zg_zipcode =
'$zipcode'";
Or (my favorite choice) you can break the string and add the variable with
.'s:
	$sql_query = "select zg_longitude from zip_code where zg_zipcode =
'" . $zipcode . "'";
With the first option, it is not always clear what is the variable and what
not.

Jos

-----Original Message-----
From: ReClMaples [mailto:reclmaples@xxxxxxxxxxxxx]
Sent: 07 April 2005 06:04
To: PHP
Subject:  MySql and PHP question


All,

   I have a question as how I can return some results that I am looking
for.  Ideally I'd like to run this sql statement but for some reason MySql
won't allow me to run it:


SELECT * FROM zip_code WHERE zg_latitude between ((select zg_latitude from zip_code where zg_zipcode = '78730')- 2) and ((select zg_latitude from zip_code where zg_zipcode = '78730') + 2) and zg_longitude between ((select zg_longitude from zip_code where zg_zipcode = '78730') - 2) and ((select zg_longitude from zip_code where zg_zipcode = '78730') + 2)

I get an error to check the mysql manual.  This statement runs in an oracle
environment though.

I guess I am stuck with writing multiple queries and them tying them
together.  In PHP how can I put a variable into the sql statement (if that's
possible).  Let's say I have these queries:
select zg_longitude from zip_code where zg_zipcode = '78730'

This one pulls the zg_longitude from the zip_code table where the zip_code
is 78730 for instance.  I want to take the result (one record) and put it in
this sql statment replacing 'result here':

select * from zip_code
where zg_longitude >= ('result here'-2)
and zg_longitude <= ('result here'+2)
order by zg_city asc

Can anyone help me with this or point me in a better direction?

Thanks

-Rich




-- Experience is a good teacher, but she sends in terrific bills.

Minna Antrim

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux