首页 > 代码库 > php keywords select

php keywords select

视图:

<form action="select_like.php" method="post">
<table class="search-tab">
<tr>
<th width="120">选择分类:</th>
<td>
<select name="search-sort" id="">
<option value="">全部</option>
<option value="http://www.mamicode.com/19">运动健身</option>
<option value="http://www.mamicode.com/20">旅游</option>
<option value="http://www.mamicode.com/21">文学艺术</option>
<option value="http://www.mamicode.com/22">演讲</option>
<option value="http://www.mamicode.com/23">经济</option>
<option value="http://www.mamicode.com/24">电影</option>
<option value="http://www.mamicode.com/25">科技</option>
<option value="http://www.mamicode.com/26">美食</option>
</select>
</td>
<th width="70">关键字:</th>
<td><input class="common-text" placeholder="关键字" name="keywords" value="" id="" type="text"></td>
<td><input class="btn btn-primary btn2" name="sub" value="http://www.mamicode.com/查询" type="submit"></td>
</tr>
</table>
</form>

控制器:

<?php
// var_dump($_POST);
$con = mysql_connect("localhost",‘root‘,‘12‘);
mysql_select_db(‘news‘,$con);
mysql_query(‘set names utf8‘);
$arrAll = array();
if (!empty($_POST[‘keywords‘])) {
$keywords = $_POST[‘keywords‘];
// echo "select * from newsup where `title` like ‘%{$keywords}%‘";
$result = mysql_query("select * from newsup where `title` like ‘%{$keywords}%‘") or die(‘select fail‘);
while ($row = mysql_fetch_assoc($result)) {
$arrAll[] = $row;
}
}else{

$result = mysql_query("select * from newsup") or die(‘select fail‘);
while ($row = mysql_fetch_assoc($result)) {
$arrAll[] = $row;
}
}
?>

php keywords select