blasterstudios
Technical User
Well, first of, this doesn't work. I don't know why. For some reason, my WHERE string is not being created. secondly, is there an easier way to do this?
all of the $_GET['s*'] variables are submitted via the advanced search. for instance $_GET['sa1] is the address1 field of the search. is there something i need to do like rawurlencode() or something to get this to work? My fields are name, title, organization, phone1, phone2, fax, email, website, city, state, zip, and some others... What looks wrong?
Code:
$like = "";
if(isset($_GET['s']) && $_GET['s'] != ""){
$trimmed = trim($_GET['s']);
$like1 = " contactname LIKE '%$trimmed%'";
$like = $like1;
}
if(isset($_GET['sn']) && $_GET['sn'] != ""){
$sn = trim($_GET['sn']);
$like2 = " contactname LIKE '%$sn%'";
if($like != ""){
$like = $like." AND".$like2;
}
}
if(isset($_GET['st']) && $_GET['st'] != ""){
$st = trim($_GET['st']);
$like3 = " title LIKE '%$st%'";
if($like != ""){
$like = $like." AND".$like3;
}
}
if(isset($_GET['so']) && $_GET['so'] != ""){
$so = trim($_GET['so']);
$like4 = " organization LIKE '%$so%'";
if($like != ""){
$like = $like." AND".$like4;
}
}
if(isset($_GET['sa1']) && $_GET['sa1'] != ""){
$sa1 = trim($_GET['sa1']);
$like5 = " address1 LIKE '%$sa1%'";
if($like != ""){
$like = $like." AND".$like5;
}
}
if(isset($_GET['sa2']) && $_GET['sa2'] != ""){
$sa2 = trim($_GET['sa2']);
$like6 = " address2 LIKE '%$sa2%'";
if($like != ""){
$like = $like." AND".$like6;
}
}
if(isset($_GET['sc']) && $_GET['sc'] != ""){
$sc = trim($_GET['sc']);
$like7 = " city LIKE '%$sc%'";
if($like != ""){
$like = $like." AND".$like7;
}
}
if(isset($_GET['ss']) && $_GET['ss'] != ""){
$ss = trim($_GET['ss']);
$like8 = " state LIKE '%$ss%'";
if($like != ""){
$like = $like." AND".$like8;
}
}
if(isset($_GET['st']) && $_GET['st'] != ""){
$st = trim($_GET['st']);
$like9 = " zip LIKE '%$st%'";
if($like != ""){
$like = $like." AND".$like9;
}
}
if(isset($_GET['sp1']) && $_GET['sp1'] != ""){
$sp1 = trim($_GET['sp1']);
$like10 = " phone1 LIKE '%$sp1%'";
if($like != ""){
$like = $like." AND".$like10;
}
}
if(isset($_GET['sp2']) && $_GET['sp2'] != ""){
$sp2 = trim($_GET['sp2']);
$like11 = " phone2 LIKE '%$sp2%'";
if($like != ""){
$like = $like." AND".$like11;
}
}
if(isset($_GET['sf']) && $_GET['sf'] != ""){
$sf = trim($_GET['sf']);
$like12 = " fax LIKE '%$sf%'";
if($like != ""){
$like = $like." AND".$like12;
}
}
if(isset($_GET['se']) && $_GET['se'] != ""){
$s3 = trim($_GET['se']);
$like13 = " email LIKE '%$se%'";
if($like != ""){
$like = $like." AND".$like13;
}
}
if(isset($_GET['sw']) && $_GET['sw'] != ""){
$sw = trim($_GET['sw']);
$like14 = " website LIKE '%$sw%'";
if($like != ""){
$like = $like." AND".$like14;
}
}
if(isset($_GET['l'])){
if($like != ""){
$like = $like." AND (contactname LIKE '".$_GET['l']."%' OR contactname LIKE '% ".$_GET['l']."%')";
} else {
$like = " contactname LIKE '".$_GET['l']."%' OR contactname LIKE '% ".$_GET['l']."%'";
}
}
$where = "";
if($like != ""){
$where = " WHERE";
}
$query_getcontacts = "SELECT * FROM hgs_contacts".$where.$like.$sort;
all of the $_GET['s*'] variables are submitted via the advanced search. for instance $_GET['sa1] is the address1 field of the search. is there something i need to do like rawurlencode() or something to get this to work? My fields are name, title, organization, phone1, phone2, fax, email, website, city, state, zip, and some others... What looks wrong?