RE: [PHP-DB] MySql and PHP question
| From: | Jeffrey D. Means | Date: | Sun, 10 Apr 2005 09:09:07 +0000 |
| Subject: | RE: [PHP-DB] MySql and PHP question | ||
| References: | 1 | Groups: | php.db php.db php.db |
| Request: | Send a blank email to php-db+get-39158@lists.php.net to get a copy of this message | ||
You are probably running mysql 3.x if you move to 4.x or the beta 5.x
you can use subqueries and even user functions in 5.x
hope this helps...
On Thu, 2005-04-07 at 08:50 +0200, 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@sbcglobal.net]
> Sent: 07 April 2005 06:04
> To: PHP
> Subject: [PHP-DB] 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
>
--
Jeffrey D. Means meaje@meanspc.com
Owner / CIO for MeansPC http://www.meanspc.com/
Custom Web Development For Your Needs. (970)308-1298
My Public PGP Key ID is: 0x81F00126
and available via:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x81F00126
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc