Gossamer Forum
Home : General : Databases and SQL :

Variables in a query...

Quote Reply
Variables in a query...
In my query string, why does this work...

"(MaxPrice <= '11')"

and this doesn't...

"(MaxPrice <= '{$_POST['Keyword']}')" ???



I have attempted to force this by specifying type, but nothing seems to work!
Quote Reply
Re: [jharwood] Variables in a query... In reply to
Because you have the single quotes in the _POST variable...you need to do the following:

$Keyword = $_POST['Keyword'];

Then change the where clause to:

(MaxPrice <= '$Keyword')
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Variables in a query... In reply to
Thanks Stealth for your quick reply!

I had already tried what you suggest, and I'm completely stumped as to why it doesn't work. Here's what I get...

Putting an "11" or "'11'" directly into the query renders the following correct results (30 results between $4.00 - $10.00):

4.00, 4.30, 4.60, 5.30, 5.46, 5.87, 5.96, 6.10, 6.96, 7.00, 7.00, 7.00, 8.30, 8.76, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00.

Anything else, including your suggestion, renders the following (10 results between $4.30 - $10.00):

4.30, 5.46, 5.87, 8.30, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00.

Go Figure!
Quote Reply
Re: [jharwood] Variables in a query... In reply to
What is the column type of the MaxPrice?

You might consider also using BETWEEN operator in the WHERE clause.

Like:

WHERE (MaxPrice BETWEEN 1 AND 11)
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Variables in a query... In reply to
The column type is decimal(10,2).

I'll try the "between" approach now.
Quote Reply
Re: [Stealth] Variables in a query... In reply to
Well, that didn't work either. It's sort of beyond frustrating, it's become more of a strange fascination now.
Quote Reply
Re: [jharwood] Variables in a query... In reply to
Since it is a decimal column type, you shouldn't have to put the single quotes around the form field parameter.

Just do:

(MaxPrice <= $Keywords)
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Variables in a query... In reply to
OK, I've spent the last hour going through this array of options...

$Keyword = $_POST[$Keyword] / (MaxPrice <= $Keyword)

$Keyword = $_POST['$Keyword'] / (MaxPrice <= $Keyword)

$Keyword = '$_POST[$Keyword]' / (MaxPrice <= $Keyword)

$Keyword = '$_POST['$Keyword']' / (MaxPrice <= $Keyword)

$Keyword = $_POST[$Keyword] / (MaxPrice <= '$Keyword')

$Keyword = $_POST['$Keyword'] / (MaxPrice <= '$Keyword')

$Keyword = '$_POST[$Keyword]' / (MaxPrice <= '$Keyword')

$Keyword = '$_POST['$Keyword']' / (MaxPrice <= '$Keyword')

(MaxPrice <= $_POST[$Keyword])

(MaxPrice <= $_POST['$Keyword'])

(MaxPrice <= '$_POST[$Keyword]')

(MaxPrice <= '$_POST['$Keyword']')

(MaxPrice <= {$_POST[$Keyword]})

(MaxPrice <= {$_POST['$Keyword']})

(MaxPrice <= {'$_POST[$Keyword]'})

(MaxPrice <= {'$_POST['$Keyword']'})

(MaxPrice <= '{$_POST[$Keyword]}')

(MaxPrice <= '{$_POST['$Keyword']}')

(MaxPrice <= '{'$_POST[$Keyword]'}')

(MaxPrice <= '{'$_POST['$Keyword']'}'),

If they didn't error they gave the same old incorrect results;

4.30, 5.46, 5.87, 8.30, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00.
Quote Reply
Re: [jharwood] Variables in a query... In reply to
Any other suggestions out there? I'm still looking for a solution to this fascinating problem.