Personal Loans - Refinance - Credit Cards - Loans - Singapore Shopping Guide

PDA

View Full Version : Syntax probs


pangea
Mar 21st 2007, 3:08 pm
Hi,

Can anyone tell me the correct syntax to search for values above or equal to the entered amount in a form:

<?
$SHQuery = "select * from add_property where ";
if($_REQUEST[status]!=""){
$SHQuery.= "status like '%$_REQUEST[status]%' and ";
}

if($_REQUEST[city]!=""){
$SHQuery.= "city like '%$_REQUEST[city]%' and ";
}

if($_REQUEST[state]!=""){
$SHQuery.= "state like '%$_REQUEST[state]%' and ";
}

if($_REQUEST[country]!=""){
$SHQuery.= "country like '%$_REQUEST[country]%' and ";
}

if($_REQUEST[bedrooms]!=""){
$SHQuery.= "bedrooms between '%$_REQUEST[bedrooms]%' and ";
}

$SHQuery = substr($SHQuery, 0, -4) ;

//echo $SHQuery;die();

$SHResult= mysql_query($SHQuery) or die(mysql_error());
if(mysql_num_rows($SHResult)>0){
?>

I tried >= and <= and greater than but it doesnt work!!

would appreciate any ideas - thanks guys!

hamidof
Mar 21st 2007, 3:42 pm
Take out that last and
Also <= & >= work fine.

pangea
Mar 22nd 2007, 1:21 pm
hamidof,

thanks ill try that but it didnt like it last time......ill check again - thanks for your time

pangea
Mar 22nd 2007, 1:22 pm
if i take out the and, i got the error that ' and " cant go next to each other. do i leave a space?

hamidof
Mar 23rd 2007, 10:08 pm
Can you post the exact error.
Also it's a very bad idea to query the database with the exact user input, you should take a look at:
http://in2.php.net/mysql_real_escape_string

srobona
Mar 23rd 2007, 11:33 pm
if($_REQUEST[status]!=""){

Try this line like following:
if($_REQUEST['status']!=""){

TwistMyArm
Mar 24th 2007, 5:56 am
I also think you'll find that you'll do better without the percentage signs on either side of the values you are testing against. I was under the impression that they are used for strings, not numbers...

Rasczak
Mar 24th 2007, 12:35 pm
I also think you'll find that you'll do better without the percentage signs on either side of the values you are testing against. I was under the impression that they are used for strings, not numbers...

you're right... as well, that multi-IFfy code could be made a little bit more re-readable ;-) i will try to find out a shorter way...