Forms
|
|
|
|
<?php //////////////////////////////////////////////////////////////
// Parameters :
// $tableName: name of table query string is to used on
// $conOrDis : "and" if where clause is conjuctive
// "or" if where clause is disjunctive
function qStrGen($tableName,$conOrDis) {
Global $HTTP_POST_VARS;
$qStr = "select * from $tableName where ";
$count = 0;
while(list($key,$val) = each($HTTP_POST_VARS)) {
if(!strcmp("update",$key) || strstr($key,"Form")) { //not included in qStr
continue;
}
else if($val) {
if($count) { //check to see if first condition in where clause
$qStr .= " ".$conOrDis." ";
}
if(strstr($key,"addr") || !strcmp($key,"fname") || !strcmp($key,"name")) { //allow for partial matching
$qStr .= "$key like "%$val%"";
}
else
$qStr .= "$key="$val"";
++$count;
}
}
$qStr .= ";";
if(!$count){ //empty where clause...set qStr to zero or whatever
$qStr = "0";
}
return($qStr);
} ?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|