0
我正在將分類的廣告/平面文件perl腳本轉換爲使用mysql/dbi; 我有這個搜索代碼,它不工作得很好。它會從item_category中找到Vintage_Trailers,但是如果我包含item_state,它將找不到任何東西。我需要它僅在內華達州找到Vintage_Tilers。但用戶不能選擇一個狀態,所以只能找到Vintage_trailers。或者,也許只有關鍵字'沙斯塔'......我可以修改的某些「開箱即用」功能非常出色。任何幫助表示讚賞。高級搜索代碼
$searchfor="$multi_input $keywords $user $item_category $item_city $item_state";
my $dsn = "DBI:mysql:$database";
my $dbh = DBI->connect($dsn, $userid, $password)
or die $DBI::errstr;
my @searchthings = split(/ /,$searchfor);
foreach $thing(@searchthings)
{
if ($thing){
$statement .= "(item_name like '%$thing%' or
item_desc like '%$thing%' or
item_desc2 like '%$thing%' or
item_category like '%$thing%' or
item_city like '%$thing%' or
item_state like '%$thing%' or
user like '%$thing%') ";
}
}
$sth = $dbh->prepare(qq(select * from ads where $statement)) or die $DBI::errstr;
$sth->execute();
while ((my (@rows)) = $sth->fetchrow_array)
{
$total_row_count= $sth->rows;
$database_rows = join ("\|", @rows);
push (@database_rows,$database_rows);
}
$sth->finish() or die $DBI::errstr;
$dbh->disconnect() or die $DBI::errstr;