我正在尝试上传一个CSV
文件,该文件中存在我要与该号码匹配的序列号,然后使用PHP
从该匹配号中找到一些关键字作为数据库搜索?请更正我的代码以搜索该关键字我不知道我的代码如何工作?请建议使用preg_match方法来查找“皇室魔王”之类的关键字。
//import.php
echo "<pre>";
//print_r($_POST);die();
$keyword = $_POST['keyword'];
$csvname = $_POST['csv_file'];
$row = 0;
if (($handle = fopen("idata.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
// echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
$query = "SELECT * FROM wm_article WHERE id = '".$data[$c]."'";
$exec = mysqli_query($conn, $query);
$details = mysqli_fetch_array($exec);
$description = $details['title'] ." ".$details['description'];
echo $description ;
$aKeyword = explode(" ", $_POST['keyword']);
$query ="SELECT * FROM wm_article WHERE description like '%" . $aKeyword[0] . "%'";
for($i = 1; $i < count($aKeyword); $i++) {
if(!empty($aKeyword[$i])) {
$query .= " OR wm_article like '%" . $aKeyword[$i] . "%'";
}
}
$result = $db->query($query);
}
}
fclose($handle);
}
?>