<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="keyword">
<button>搜索</button>
</form>
<?php
// $min = 0;
$maxs = 10000;
$sizePage = 10;
$currentPage = 1;
$keyWord = $_GET['keyword'];
echo "<h1>".$keyWord."</h1>";
// 创建连接
$conn = new mysqli('127.0.0.1', 'root', 'root', 'test1');
if(!$conn){
echo '连接失败', mysqli_connect_error(), "<br/>";
}
else{
echo '连接成功', "<br />";
}
// $res = mysqli_query($conn, 'select * from industry_distribution where id > 0 and id < 21');
$res = mysqli_query($conn, 'select * from industry_distribution where (label like "%'.$keyWord.'%" or name like "%'.$keyWord.'%") and id < '.$maxs.' ');
// $rows = mysqli_num_rows($res);
// $rows = count($res, COUNT_RECURSIVE);
// echo $rows;
// for($i=0;$i<$rows;$i++){
// $arr=mysqli_fetch_array($res);
// echo $arr['id'],$arr['name'];
// }
// echo count($res, COUNT_RECURSIVE);
// echo gettype($res);
echo '查询到的记录条数:',mysqli_num_rows($res);
// echo var_dump(is_array($res)); // bool(false)
// echo mysqli_num_rows($res);
echo '<table border="1">
<th>id</th>
<th>name</th>
<th>company</th>
<th>indystry</th>
<th>label</th>
';
$i = 1;
while($row = mysqli_fetch_array($res)){
echo '<tr><td>'. $i .'</td><td>'.$row['name'],'</td><td>', $row['company'],'</td><td>', $row['indystry']."</td><td>",$row['label'],"</td></tr>";
$i++;
}
echo '</table>';
mysqli_close($conn);
?>
</body>
</html>
php连接MySQL数据并做模糊查询
最新推荐文章于 2022-07-12 16:48:53 发布