我创建了一个视图,其中合并了需要搜索的所有ID。
每份工作都有标签
我的问题是标签,我使用LIKE进行具有多个值的搜索,但是当我标记多个标签并进行搜索时,搜索返回的结果就像我一次搜索1个服务。 / p>
例如:我写了研究领域的文章(1 2 3)。如果“ job1”的标签为“ 1”,而“ job2”的标签为“ 1”,“ 2”和“ 3”,则搜索仅返回“ job2”,但返回2个工作。
我已经尝试过使用implode()CONCAT(),但是我不知道如何正确地为该沙丘使用no select
$query = "SElECT * FROM tbBiodata WHERE nama LIKE :q OR hp LIKE :q";
或处理输入操作错误
<input type="text" name="q" placeholder="tag" value="<?php if (isset($_GET['q'])){ echo $_GET['q']; } ?>"/>
代码我正在使用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jobs</title>
</head>
<body>
<h1> Data</h1>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="q" placeholder="tag" value="<?php if (isset($_GET['q'])){ echo $_GET['q']; } ?>"/>
</form>
</body>
</html>
<?php
if (isset($_GET['q'])){
$q = $_GET['q'];
$query = "SElECT * FROM tbBiodata WHERE nama LIKE :q OR hp LIKE :q";
$q = "%".$q."%"; ////tambahkan tanda persen pada variabel $q
$stmt = $db->prepare($query); // prepare the query
$stmt->bindParam(':q', $q); // fill in the value: q from $ q y
$stmt->execute(); // query execution
$jml = $stmt->rowCount(); // check the amount of data from the query
if ($jml>0){ //jika ada data tampilkan
echo "<table border=\"1\">
<tr>
<th>No</th>
<th>ID</th>
<th>job</th>
<th>info</th>
<th>cas</th>
</tr>";
$no=1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);// change $ row ['field'] to {$ field}
echo "<tr>
<td>$no</td>
<td>{$id}</td>
<td>{$nama}</td>
<td>{$alamat}</td>
<td>{$hp}</td>
</tr>";
$no++;
}
echo "</table>";
} else {
echo "Search <b>$_GET[q]</b> not found";
}
}
?>