嗨,我一直在試圖創建一個像搜索引擎一樣的程序。因此,這裏就是我這麼遠:PHP在mysql中搜索多個關鍵字
我需要選擇的選擇選項的症狀,然後將其添加。
我添加的那些選項將開始在我的Mysql數據庫的每一行上進行搜索。我需要輸出我添加的每個匹配關鍵字。 這是一個真正的痛苦,所以我想知道你將如何解決這個問題。
這裏是我的代碼:
$x = 0;
for($x; $x < 10;$x++) {
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a0']}%' AND id = $x ";
$sel1 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a1']}%' AND id = $x ";
$sel2 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a2']}%' AND id = $x ";
$sel3 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a3']}%' AND id = $x ";
$sel4 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a4']}%' AND id = $x ";
$sel5 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a5']}%' AND id = $x ";
$sel6 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a6']}%' AND id = $x ";
$sel7 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a7']}%' AND id = $x ";
$sel8 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a8']}%' AND id = $x ";
$sel9 = mysqli_query($connect,$selx);
$selx = "SELECT * FROM sicks WHERE tags LIKE '%{$_POST['a9']}%' AND id = $x ";
$sel10 = mysqli_query($connect,$selx);
$c1 = mysqli_num_rows($sel1);
$c2 = mysqli_num_rows($sel2);
$c3 = mysqli_num_rows($sel3);
$c4 = mysqli_num_rows($sel4);
$c5 = mysqli_num_rows($sel5);
$c6 = mysqli_num_rows($sel6);
$c7 = mysqli_num_rows($sel7);
$c8 = mysqli_num_rows($sel8);
$c9 = mysqli_num_rows($sel9);
$c10 = mysqli_num_rows($sel10);
$q2 = mysqli_query($sel2);
$q3 = mysqli_query($sel3);
$q4 = mysqli_query($sel4);
$q5 = mysqli_query($sel5);
$q6 = mysqli_query($sel6);
$q7 = mysqli_query($sel7);
$q8 = mysqli_query($sel8);
$q9 = mysqli_query($sel9);
$q10 = mysqli_query($sel10);
$q1 = mysqli_query($sel1);
$row = mysqli_fetch_array($q2);
$_SESSION['news'] = $row['tags'];
$every = $c1 + $c2 + $c3 + $c4 + $c5 + $c6 + $c7 + $c8 + $c9 ;
echo $every;
}
的{$_POST['a0']}
,{$_POST['a1']}
...是關鍵字從選擇選項來了。
我的javascript:
$('.sendit').click(function() {
a0 = $('.a0').val();
a1 = $('.a1').val();
a2 = $('.a2').val();
a3 = $('.a3').val();
a4 = $('.a4').val();
a5 = $('.a5').val();
a6 = $('.a6').val();
a7 = $('.a7').val();
a8 = $('.a8').val();
a9 = $('.a9').val();
a10 = $('.a10').val();
$.ajax({
url:"function.php?sendit=true",
type:"post",
data:{a0:a0,
a1:a1,
a2:a2,
a3:a3,
a4:a4,
a5:a5,
a6:a6,
a7:a7,
a8:a8,
a9:a9,
a10:a10},
success:function(data) {
$('.texta').html(data);
}
});
return false;
});
非常感謝:)但我想要的是統計所有匹配的標籤,以便輸出最匹配的數據。 – Rongiro