Page 1 of 1

Select Key=Value from a SQL WHERE clause

Posted: Sun Oct 30, 2011 5:12 pm
by markjohnson
Hi,

I have a SQL statement:
$sql='SELECT PROPID, ADDRESS_1, ADDRESS_2, TOWN, POSTCODE1, POSTCODE2, BEDROOMS, BATHROOMS, RECEPTIONS, PRICE, TRANS_TYPE_ID FROM properties WHERE TRANS_TYPE_ID=2 AND BEDROOMS =3 AND PROP_SUB_ID IN (1,2,3,4,5,6,21,22,23,24,27,30,95,128,131) ORDER BY DATE_ADDED, PROPID DESC';

I want to be able to get the fields and their corresponding values as such:

$result['TRANS_TYPE_ID']=2;
$result['BEDROOMS']=3;

And then capture the values in PROB_SUB_IN IN(*)

How can I do this?

Any help will be greatly appreciated. Thanks

Re: Select Key=Value from a SQL WHERE clause

Posted: Sun Oct 30, 2011 6:36 pm
by Weirdan
Can't you get them from where this sql query was created?

Re: Select Key=Value from a SQL WHERE clause

Posted: Sun Oct 30, 2011 7:44 pm
by markjohnson
Some of these queries would be saved separately. I would like to fetch the saved queries and extract some of the key fields from WHERE clause and their values.

Re: Select Key=Value from a SQL WHERE clause

Posted: Mon Oct 31, 2011 3:49 am
by Weirdan
You'll need to find (or build) an sql parser then.