Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT QUERY LIKE

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
Hi htere im using Windowx Xp Home , php and apache i nthe normal way

I have the following problem

ok im running the following sql query in a php script

$search= mysql_query("SELECT * FROM propertyforsale WHERE NoBedrooms>=$minBed AND Region LIKE '%'$leicester");

The problem lies with the LIKE section of the query. It cant recognise the string, it leaves it as blank so something, i have tried so many ways of writing the like section e.g.

Region LIKE '%$leicester'
Region LIKE \"'%$leicester'\"
etc etc.. but cant seem to get it owrking
i thought i did get it working
BUT when i added the second like to it, it messed up

I dont know how im supposed to write the LIKE bit of the statement so that it work like it does in mySQL
I ran the same SQL in mySQL with a few tweeks and it worked perfectly

please could someone help

thanks in advance

sanj
 
Sanj,

I am not entirely sure if you want to treat leicester as a variable or as text. You are mixing both uses.

To use it as a variable in a clean way:
$SQL = "SELECT * FROM propertyforsale WHERE NoBedroom >= $minBed AND Region LIKE '%".$leicester."'";

If you just want to use the string leicester:
$SQL = "SELECT * FROM propertyforsale WHERE NoBedroom >= $minBed AND Region LIKE '%leicester'";

Echo the SQL string, so you can check when submitting the page with the search parameters.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top