PHP 개발 쿼리 검색 사용자 쿼리

사용자 쿼리

QQ截图20161201143744.png

데이터베이스 연결

<?php
$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
$conn = @mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("sql", $conn);
mysql_query("set names 'utf8'"); //使用utf-8中文编码;
?>

을 실행한 다음 데이터베이스에 대해 퍼지 쿼리를 수행합니다.

<?php
$sql="SELECT * FROM user WHERE username LIKE '%{$keywords}%'";
$rs= mysql_query($sql);
$users = array();//保存所以得查询到的用户
?>

퍼지 쿼리 문을 사용하여 모든 사용자를 쿼리하고

$users에 저장하세요. 우리는 얻은 데이터를 계속 쓰고 루프하고 있습니다. 우리는 Page

<?php
if ($keywords){
    echo '<h3>查询关键词:<font color="red">'.$keywords.'</font></h3>';
}
if ($users){
    echo '<table width="500" cellpadding="5">';
    echo '<tr><th>用户名</th><th>密码</th><th>邮箱</th><th>性别</th><th>爱好</th>';
    foreach ($users as $key=>$value){
        echo '<tr>';
        echo '<td>'.$value['username'].'</td>';
        echo '<td>'.$value['password'].'</td>';
        echo '<td>'.$value['sex'].'</td>';
        echo '<td>'.$value['email'].'</td>';
        echo '<td>'.$value['hobby'].'</td>';
        echo '</tr>';
    }
}else{
    echo '没有查询到相关用户';
}
?>

를 아름답게합니다. 그래서 우리의 데이터는이 장의 Key Points가 표시되도록합니다. QQ截图20161105114257.pngSQL을 사용하여 데이터베이스에서 퍼지 쿼리 수행


PHP 및 html 문 혼합

지속적인 학습
||
<?php $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : ''; $conn = @mysql_connect("localhost", "root", "root") or die("数据库链接错误"); mysql_select_db("sql", $conn); mysql_query("set names 'utf8'"); //使用utf-8中文编码; //PHP模糊查询 $sql="SELECT * FROM user WHERE username LIKE '%{$keywords}%'"; $rs= mysql_query($sql); $users = array();//保存所以得查询到的用户 if(!empty($keywords)){ while ($row=mysql_fetch_assoc($rs)){ $users[] = $row; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>查询器</title> <style> .textbox { width: 355px; height: 40px; border-radius: 3px; border: 1px solid #e2b709; padding-left: 10px; } .su { width: 365px; height: 40px; background-color: #7fbdf0; color: white; border: 1px solid #666666; } table{ background-color: #7fbdf0; line-height:25px;} th{ background-color:#fff;} td{ background-color:#fff; text-align:center} </style> </head> <body > <form action="" method="get"> <p><input type="text" name="keywords" class="textbox" value="" placeholder="请输入内容"/> <p><input type="submit" class="su" value="查询"/> </form> <?php if ($keywords){ echo '<h3>查询关键词:<font color="red">'.$keywords.'</font></h3>'; } if ($users){ echo '<table width="500" cellpadding="5" >'; echo '<tr><th>用户名</th><th>密码</th><th>邮箱</th><th>性别</th><th>爱好</th>'; foreach ($users as $key=>$value){ echo '<tr>'; echo '<td>'.$value['username'].'</td>'; echo '<td>'.$value['password'].'</td>'; echo '<td>'.$value['sex'].'</td>'; echo '<td>'.$value['email'].'</td>'; echo '<td>'.$value['hobby'].'</td>'; echo '</tr>'; } }else{ echo '没有查询到相关用户'; } ?> </body> </html>
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!