phpnstuff
05-12-2006, 11:11 AM
If I will search by a code or the agency name, it finds records easy and
display the results, but if I search any words they have in their description, it won't display any results, am i doing something wrong?
This is how its in the database:
agency_code: 1234
name: xyz agency
description: blah blah we are xyz agency that specializes in child abuse.
If I search for 1234 it display their info in the results, if I search for xyz agency it works also, but if I put in "child abuse" it won't find that data in the description of the database and displays no records.
<?php
include '../includes/mysql/sql_connection.php';
//Select Database
$dbname = "cap";
$dbconn = mysql_connect ( $dbhost, $dbuser, $dbpass );
mysql_select_db( $dbname, $dbconn );
//Remove Case-Sensitive
$q = strtoupper($q);
//Remove Common Words
$q = str_replace('AND', '', $q);
$q = str_replace('&', '', $q);
$q = str_replace('OR', '', $q);
$q = str_replace('IF', '', $q);
$q = str_replace('OF', '', $q);
//Seperate Words - WORD|WORD|WORD
$q = strtoupper(preg_replace('/\s+/', '|', trim($q)));
//Keep Symbols
$regexp = "REGEXP '[[:<:]]($q)[[:>:]]'";
$result = mysql_query("SELECT COUNT(*) FROM `company_information` WHERE UPPER(`name`) $regexp" . " OR UPPER(`description`) $regexp" . " OR UPPER(`agency_code`) $regexp", $dbconn);
$record_count = mysql_result($result, 0);
if($record_count > "0") {
//Execute The Data
$query = "SELECT * FROM `company_information` WHERE UPPER(`description`) $regexp" . " OR UPPER(`name`) $regexp" . " OR UPPER(`agency_code`) $regexp";
$result = mysql_query( $query ) or die( mysql_error() );
while($record = mysql_fetch_assoc( $result ))
{
echo" <tr>\n";
echo" <td>\n";
echo " <a href=\"../community_impact/url.php?loc=certified_agency_partners#".$record['agency_code']."\" onMouseOver=\"(window.status='".str_replace("'", "\'", $record['name'])."'); return true\" class=\"content_body_link\">".$record['name']."</a></li>\n";
echo" </td>\n";
echo" </tr>\n";
}
} else {
echo "no records found";
}
?>
display the results, but if I search any words they have in their description, it won't display any results, am i doing something wrong?
This is how its in the database:
agency_code: 1234
name: xyz agency
description: blah blah we are xyz agency that specializes in child abuse.
If I search for 1234 it display their info in the results, if I search for xyz agency it works also, but if I put in "child abuse" it won't find that data in the description of the database and displays no records.
<?php
include '../includes/mysql/sql_connection.php';
//Select Database
$dbname = "cap";
$dbconn = mysql_connect ( $dbhost, $dbuser, $dbpass );
mysql_select_db( $dbname, $dbconn );
//Remove Case-Sensitive
$q = strtoupper($q);
//Remove Common Words
$q = str_replace('AND', '', $q);
$q = str_replace('&', '', $q);
$q = str_replace('OR', '', $q);
$q = str_replace('IF', '', $q);
$q = str_replace('OF', '', $q);
//Seperate Words - WORD|WORD|WORD
$q = strtoupper(preg_replace('/\s+/', '|', trim($q)));
//Keep Symbols
$regexp = "REGEXP '[[:<:]]($q)[[:>:]]'";
$result = mysql_query("SELECT COUNT(*) FROM `company_information` WHERE UPPER(`name`) $regexp" . " OR UPPER(`description`) $regexp" . " OR UPPER(`agency_code`) $regexp", $dbconn);
$record_count = mysql_result($result, 0);
if($record_count > "0") {
//Execute The Data
$query = "SELECT * FROM `company_information` WHERE UPPER(`description`) $regexp" . " OR UPPER(`name`) $regexp" . " OR UPPER(`agency_code`) $regexp";
$result = mysql_query( $query ) or die( mysql_error() );
while($record = mysql_fetch_assoc( $result ))
{
echo" <tr>\n";
echo" <td>\n";
echo " <a href=\"../community_impact/url.php?loc=certified_agency_partners#".$record['agency_code']."\" onMouseOver=\"(window.status='".str_replace("'", "\'", $record['name'])."'); return true\" class=\"content_body_link\">".$record['name']."</a></li>\n";
echo" </td>\n";
echo" </tr>\n";
}
} else {
echo "no records found";
}
?>