RE: [PHP-DB] MySql and PHP question
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:[EMAIL PROTECTED]] 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 [EMAIL PROTECTED] 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=getsearch=0x81F00126 signature.asc Description: This is a digitally signed message part
RE: [PHP-DB] MySql and PHP question
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:[EMAIL PROTECTED] 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySql and PHP question
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:[EMAIL PROTECTED] 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 -- 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
Re: [PHP-DB] MySql and PHP question
subselects are available as of 4.1 bastien From: graeme [EMAIL PROTECTED] To: Juffermans, Jos [EMAIL PROTECTED] CC: 'php-db@lists.php.net' php-db@lists.php.net Subject: Re: [PHP-DB] MySql and PHP question Date: Thu, 07 Apr 2005 12:55:13 +0600 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:[EMAIL PROTECTED] 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 -- 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php