Forum Moderators: coopster

Message Too Old, No Replies

Select Statement Acting Like 'Like'

         

mhoctober

7:59 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



Guys...

I construct a select statement using input from a user form...

$query="SELECT * FROM tblPeople where fldTelNumber='$frmTelNumber' ORDER BY `fldDateCreated` DESC";

However - if the user input is 123 and in the mqSQL db there are the following tel numbers...

123 and 123456 - my select statement is returning both? I was expecting it only to return the one that it matches exactly i.e. 123?

Am I able to refine the select statement so that it ONLY returns the exact value entered by the user?

Many thanks

coopster

11:21 pm on Jan 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think you better dump that query and make sure it is exactly as you say,

SELECT * FROM tblPeople where fldTelNumber='123' ORDER BY `fldDateCreated` DESC

That query, when run against either a character or numeric column definition (fldTelNumber), will return only those rows where fldTelNumber has the exact value of 123.

Dump the $query to your browser to be sure.

mhoctober

11:35 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



Coopster....thanks for the reply.

Not sure what you mean when you refer to 'Dump the $Query to your browser'?

Can you explain in a little more detail for me please?

Many thanks

coopster

11:43 pm on Jan 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure. I meant to stop at that point in your processing and dump the variable out to the browser (and optionally exit the script, which is what I usually do) so you can confirm the query is what you expect and possibly even run the query from a command line interface.

$query="SELECT * FROM tblPeople where fldTelNumber='$frmTelNumber' ORDER BY `fldDateCreated` DESC"; 
exit("$query");
...

mhoctober

9:34 am on Jan 25, 2006 (gmt 0)

10+ Year Member



Coopster txs!

All worked out - wasnt looking for the obvious (there were 2 records that matched 123!)

Funny how we go often go looking for the hard stuff first heh?

Dumping out to the browser helped me realise where I sholud go look.

Cheers