从行sql数据库中的特殊字符开始搜索

时间:2020-10-04 07:17:33

标签: php jquery mysql ajax

我已经用AJAX和SQL查询编写了实时搜索,但是它搜索整个DOC,我只想搜索'@'后面的电子邮件和公司名称! 例如,当我输入g时,它仅显示@gmail@google@group等。 这是我的PHP代码:

<?php
//fetch.php

$connect = mysqli_connect("localhost", "root", "", "upload");
$output = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM csv 
  WHERE id LIKE '%".$search."%' 
  OR email LIKE '%".$search."%'     // <--I think i should do sth here  
  OR firstname LIKE '%".$search."%' 
  OR lastname LIKE '%".$search."%' 
 ";
}
else
{
 $query = "
  SELECT  * FROM csv ORDER BY id LIMIT 0
 ";
}

 $result = mysqli_query($connect, $query);
$rowcount=mysqli_num_rows($result);

printf("%d :نتیجه\n",$rowcount);


if(mysqli_num_rows($result)>0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>id</th>
     <th>email</th>
     <th>fisrtname</th>
     <th>lastname</th>
     
    </tr>
 ';
    
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["id"].'</td>
    <td>'.$row["email"].'</td>
    <td>'.$row["firstname"].'</td>
    <td>'.$row["lastname"].'</td>
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'چیزی برای نمایش وجود ندارد';
}

?>

0 个答案:

没有答案
相关问题