php搜索引擎添加名称搜索

时间:2018-03-05 16:05:23

标签: javascript php ajax search

这里我正在分享我的脚本,这个脚本基本上与我们学校的数据库结果有关,在脚本中,学生可以通过两个类型搜索他们的结果,按照滚动号码搜索,另一个按照名称搜索他们的考试结果,我面临的问题是通过名称搜索,当用户输入确切的名称然后从数据库中搜索,但是如果学生把他的名字的一半放在其中,那么当我把“像%$ name%”查询时,它将搜索(如)同时使用卷号和姓名可以解决我的问题吗?

<?php
if($_POST)
{
$sclass = $_POST['sclass'];
$name=$_POST['name'];
$sel=$_POST['sel'];
//echo $name;
//result_m2017
echo "Displaying Results For  " .$sel . "= " . $name ."</br>";
}
?>
<?php
//Change Table Name Here :
$tbname = "8th18a";
//if(isset($_POST['user'])){
include_once('/home/allpkres/public_html/result0/db.php');
//$name = mysql_real_escape_string($name);

$query="select * from $tbname where $name = '$sel' order by name asc";
$res    = mysqli_query($connection,$query);

$count  = mysqli_num_rows($res);
$page = (int) (!isset($_REQUEST['pageId']) ? 1 :$_REQUEST['pageId']);
$page = ($page == 0 ? 1 : $page);
$recordsPerPage = 10;
$start = ($page-1) * $recordsPerPage;
$adjacents = "2";

$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($count/$recordsPerPage);
$lpm1 = $lastpage - 1;   
$pagination = "";
if($lastpage > 1)
    {   
        $pagination .= "<div class='pagination'>";
        if ($page > 1)
            $pagination.= "<a href=\"#Page=".($prev)."\" onClick='changePagination(".($prev).");'>&laquo; Previous&nbsp;&nbsp;</a>";
        else
            $pagination.= "<span class='disabled'>&laquo; Previous&nbsp;&nbsp;</span>";   
        if ($lastpage < 7 + ($adjacents * 2))
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class='current'>$counter</span>";
                else
                    $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     

            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))
        {
            if($page < 1 + ($adjacents * 2))
            {
                for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if($counter == $page)
                        $pagination.= "<span class='current'>$counter</span>";
                    else
                        $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
                }
                $pagination.= "...";
                $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
                $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";   

           }
           elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
           {
               $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
               $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
               $pagination.= "...";
               for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
               {
                   if($counter == $page)
                       $pagination.= "<span class='current'>$counter</span>";
                   else
                       $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
               }
               $pagination.= "..";
               $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
               $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";   
           }
           else
           {
               $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
               $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
               $pagination.= "..";
               for($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
               {
                   if($counter == $page)
                        $pagination.= "<span class='current'>$counter</span>";
                   else
                        $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";     
               }
           }
        }
        if($page < $counter - 1)
            $pagination.= "<a href=\"#Page=".($next)."\" onClick='changePagination(".($next).");'>Next &raquo;</a>";
        else
            $pagination.= "<span class='disabled'>Next &raquo;</span>";

        $pagination.= "</div>";       
    }

if(isset($_POST['pageId']) && !empty($_POST['pageId']))
{
    $id=$_POST['pageId'];
}
else
{
    $id='0';
}
$query="select * from $tbname where $sel = '$name' order by name asc
limit ".mysqli_real_escape_string($connection,$start).",$recordsPerPage";
//echo $query;
$res    =   mysqli_query($connection,$query);
$count  =   mysqli_num_rows($res);
$HTML='';
if($count > 0)
{
    /*
    while($row=mysqli_fetch_array($res))
    {
        $post=$row['Name'];
        $link=$row['Marks'];
        $HTML.='<div>';
        $HTML.='<a href="'.$link.'" target="_blank">'.$post.'</a>';
        $HTML.='</div><br/>';
    }
    */


echo "<table>
<tr>
<th>Roll Number :</th>
<th>Name :</th>
<th>Father's Name :</th>
<th>School Name</th>
<th>Remarks</th>
<th>Marks</th>

</tr>";

while($row = mysqli_fetch_array($res))
  {

  echo "<tr>";
   echo "<td>" . $row['Roll_No'] . "</td>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Father Name'] . "</td>";
   echo "<td>" . $row['School Name'] . "</td>";
  echo "<td>" . $row['Desigion'] . "</td>";
  echo "<td>" . $row['Obitained'] . "</td>";

    echo "</tr>";
  }
echo "</table>";

echo "<a href='index.html'>Refresh Page </a>";




}
else
{
    $HTML= '<b>No Data Found</b>';
}
echo $HTML;
echo $pagination;

//}
?>

0 个答案:

没有答案