通过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的顺序
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-