怎么在網頁上用PHP做個搜索功能?
通過from表單,將查詢的關鍵詞,通過 like 跟數據進行模糊查詢對比
從topics表中查詢字段subject與傳進來的參數'$_POST['topic']進行比較模糊查詢
設subject字段數據為:數學,英語,物理,化學,英文
$subject=$_POST['topic'];
$sql = "select * from topics where subject like '%" .$subject. "%'";
$result = mysql_query($sql);
若從表單提交的‘topic’值為“學”,得到的結果將是:數學,化學
多個字段匹配查詢:
$sql = "select id,subject from topics where (id like '%" .$id. "%') or (name like '%" .$name. "%') or (subject like '%" .$subject. "%') order by id desc";
結果依據字段id的順序