Select Key=Value from a SQL WHERE clause

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
markjohnson
Forum Newbie
Posts: 15
Joined: Sat Feb 07, 2009 8:36 pm

Select Key=Value from a SQL WHERE clause

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Select Key=Value from a SQL WHERE clause

Post by Weirdan »

Can't you get them from where this sql query was created?
markjohnson
Forum Newbie
Posts: 15
Joined: Sat Feb 07, 2009 8:36 pm

Re: Select Key=Value from a SQL WHERE clause

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Select Key=Value from a SQL WHERE clause

Post by Weirdan »

You'll need to find (or build) an sql parser then.
Post Reply