<!-- Search form -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="search_text" size="50" maxlength="50"><input type="submit">
</form>
<?php
//jus wondering.. are u actually selecting ALL fields from the table?
//y not u jus write SELECT * in stead?
$sql = "
SELECT Name, AKA, DOB, Address, Conviction, Description, Victim, Comments, Pic
FROM sexoffenders
";
// If search_text has been sent ...
// i dun understand y do u concat all fields to be search? hmm..
if(isset($_GET['search_text'])){
$sql .= "
WHERE CONCAT(Name,' ',AKA,' ',Address,' ',Conviction,' ',Description,' ',Victim,' ',Comments,' ') LIKE
'%".$_GET['search_text']."%'
";
}
i think i can show u a better suggestion.. in stead of what u have done before, u can follow as what i'll suggest here.. but, mine involve functions (sorry if it looks complicated.. but, the results are very Damn CLEAN.. trust me)
// Get Search Criteria for Basic Search
SetUpBasicSearch();
// Build Search Criteria
if ($sSrchBasic != "") {
$sSrchWhere = $sSrchBasic; // Basic Search
}
// Build WHERE condition
$sDbWhere = "";
if ($sDbWhereMaster != "") {
$sDbWhere .= "(" . $sDbWhereMaster . ") AND ";
}
if ($sSrchWhere != "") {
$sDbWhere .= "(" . $sSrchWhere . ") AND ";
}
if (strlen($sDbWhere) > 5) {
$sDbWhere = substr($sDbWhere, 0, strlen($sDbWhere)-5); // Trim rightmost AND
}
// a complete version of SQL statement
$sSql = "SELECT * FROM `agency`";
$sGroupBy = "";
$sHaving = "";
$sWhere = "";
if ($sDbWhere != "") {
$sWhere .= "(" . $sDbWhere . ") AND ";
}
if (substr($sWhere, -5) == " AND ") {
$sWhere = substr($sWhere, 0, strlen($sWhere)-5);
}
if ($sWhere != "") {
$sSql .= " WHERE " . $sWhere;
}
if ($sGroupBy != "") {
$sSql .= " GROUP BY " . $sGroupBy;
}
if ($sHaving != "") {
$sSql .= " HAVING " . $sHaving;
}
//-------------------------------------------------------------------------------
// Function BasicSearchSQL
// - Build WHERE clause for a keyword
function BasicSearchSQL($Keyword)
{
$sKeyword = (!get_magic_quotes_gpc()) ? addslashes($Keyword) : $Keyword;
$BasicSearchSQL = "";
$BasicSearchSQL.= "`AgencyName` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`OfficeAdd1` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`OfficeAdd2` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`OfficeAdd3` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`SubdistrictName` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`DistrictName` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`EmailAdd` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`WebsiteAdd` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`OfficeNum` LIKE '%" . $sKeyword . "%' OR ";
$BasicSearchSQL.= "`FaxNum` LIKE '%" . $sKeyword . "%' OR ";
if (substr($BasicSearchSQL, -4) == " OR ") { $BasicSearchSQL = substr($BasicSearchSQL, 0, strlen($BasicSearchSQL)-4); }
return $BasicSearchSQL;
}
//-------------------------------------------------------------------------------
// Function SetUpBasicSearch
// - Set up Basic Search parameter based on form elements pSearch & pSearchType
// - Variables setup: sSrchBasic
function SetUpBasicSearch()
{
global $HTTP_GET_VARS;
global $sSrchBasic;
$sSearch = (!get_magic_quotes_gpc()) ? addslashes(@$HTTP_GET_VARS["psearch"]) : @$HTTP_GET_VARS["psearch"];
$sSearchType = @$HTTP_GET_VARS["psearchtype"];
if ($sSearch <> "") {
if ($sSearchType <> "") {
while (strpos($sSearch, " ") != false) {
$sSearch = str_replace(" ", " ",$sSearch);
}
$arKeyword = split(" ", trim($sSearch));
foreach ($arKeyword as $sKeyword)
{
$sSrchBasic .= "(" . BasicSearchSQL($sKeyword) . ") " . $sSearchType . " ";
}
}
else
{
$sSrchBasic = BasicSearchSQL($sSearch);
}
}
if (substr($sSrchBasic, -4) == " OR ") { $sSrchBasic = substr($sSrchBasic, 0, strlen($sSrchBasic)-4); }
if (substr($sSrchBasic, -5) == " AND ") { $sSrchBasic = substr($sSrchBasic, 0, strlen($sSrchBasic)-5); }
}
Shud u wana use, u have to author the code.. but i think the code is cleared enuf for you to understand everytin.. do you?
hope my code can help you solve the problem.. and as for your code, from my opinion, i think it has to be somtin wif the CONCAT thingy.. it's quite awkward tho, u search a keyword to a string of combination many fields... (HUH? i'm stil confused...)
hmm.. dun know what else to write.. i'll try to configure what's wrong wif ur codes before..
orite then.. gud luck Have a nice weeken 😃
Warm regards, videxx 🆒