如何使用php和mysql创建搜索表单

时间:2016-12-21 06:17:45

标签: php mysql

 $ch = curl_init();   
 $curlConfig = array(
 CURLOPT_URL            => "http://localhost/staff/home.php",
 CURLOPT_POST           => true,
 CURLOPT_RETURNTRANSFER => true, 
 );
 curl_setopt_array($ch, $curlConfig); 
 $result = curl_exec($ch);
 curl_close($ch);
 $decodeData = json_decode($result);
 print_r($decodeData);

3 个答案:

答案 0 :(得分:2)

在文字使用的任何地方搜索字符串'%':

$sql="SELECT * FROM test WHERE Name LIKE '%".trim($params['name'])."%'";

答案 1 :(得分:0)

<?php   if (!empty($_REQUEST['fname'])){
                    $params['name']=$_REQUEST['salute']." ".$_REQUEST['fname']." ".$_REQUEST['lname'];
                    $sql="SELECT * FROM test WHERE Name LIKE '%".trim($params['name'])."%'";  

                    $records=mysqli_query($db->conn,$sql);
                            while($row=mysqli_fetch_assoc($records)){ ?>

答案 2 :(得分:0)

要进行搜索,您必须在查询中添加%标记:

$sql="SELECT * FROM test WHERE Name LIKE '%".trim($params['name'])."%'";

尝试一下,如果可行,别忘了标记为正确。