我正在尝试为我的网页开发搜索功能。数据库中的某些列存储为表示值的整数。我有一个函数可以在返回结果时显示这些:
public function listsystypestatus($sysobj){
if ($this->sysobj ==='1') return "Core";
if ($this->sysobj ==='2') return "Aggregation";
if ($this->sysobj ==='3') return "Core/Aggr";
if ($this->sysobj ==='4') return "Customer";
if ($this->sysobj ==='5') return "TX Site";
return "--Please Select--";
我希望能够在此列上进行搜索并返回结果。例如,在“Cus”上进行通配符搜索,并返回在该列的数据库中存储为“4”的所有记录。我不知道如何解决这个问题。
我的搜索查询适用于其他(字符串)字段:
if($action=='search' && $search!=NULL){
$wildsearch = "%%$search%%";
$query = "SELECT *, INET_NTOA(ip_add) AS ip_add
FROM `equipment`
LEFT JOIN itam_asset on equipment.itamname=itam_asset.ASSETID
WHERE site_code LIKE :search
OR site_id LIKE :search
OR system_name LIKE :search
OR INET_NTOA(ip_add) LIKE :search
OR sys_loc LIKE :search
OR systype LIKE :search
OR itamname LIKE :search
OR dimetis LIKE :search
OR DNS LIKE :search
";
//Get equipment data
//select and prepare
$database->query($query);
//Bind
$database->bind(':search',$wildsearch);
}else{
....
....
Display results
我用来显示返回结果的代码是:
<?php
foreach($rows as $row){
//extract row
//this will make $row['firstname'] to
//just $firstname only
extract($row);
...
...
echo reults
...
...
谢谢大家。
编辑:新查询 - 现在有效:
$query = "SELECT *, INET_NTOA(ip_add) AS ip_add, list_systype.systype_label
FROM `equipment`
LEFT JOIN itam_asset on equipment.itamname=itam_asset.ASSETID
LEFT JOIN list_systype on equipment.systype=list_systype.systype_value
WHERE site_code LIKE :search
OR site_id LIKE :search
OR system_name LIKE :search
OR INET_NTOA(ip_add) LIKE :search
OR sys_loc LIKE :search
OR list_systype.systype_label LIKE :search
OR itamname LIKE :search
OR dimetis LIKE :search
OR DNS LIKE :search
";