如何进行实时搜索,包括onload搜索

时间:2017-07-29 05:37:11

标签: javascript php html mysql

我有一个textarea有一些价值,我需要先搜索它(onload),然后如果我改变用textarea写的文字,我需要搜索新文本(比如谷歌),当textarea为空时,我需要得到一些信息 现在我没有得到结果onload,当我尝试编辑我的文本时我得到结果,但如果我让textarea为空我得到我的桌子

function searchValue() {
    $("#search").on("input",function(){
    $search = $("#search").val();
        if($search.length!=0){
            $.get('search.php',{"s":$search},function($data){
                $("#results").html($data);
            });
        }
    });
 }

<?php
            $connection = new mysqli("localhost", "root", "root", 'google');
            $connection->query ("SET NAMES 'utf8'");
            $query="SELECT * FROM `googleSearchResult` WHERE `info` LIKE '%$_GET[s]%'";
            $data=$connection->query($query);
            while ($result = $data->fetch_assoc()){
                echo "<br><p><a href='".$result['url']."'style='color:#1a0dab !important; font-size:20px'>".$result['title']."</a></p>";
                echo "<p style='color:#006621 !important; font-size:17px'>".$result['url']."</p>";
                echo "<p style='color:#545454 !important; font-size:16px'>".$result['info']."</p>"."<br>";
            }
            $connection->close();
            ?>

<input class="textarea2" id='search' type="text" value="someValue">
                    <p id='results'></p>

1 个答案:

答案 0 :(得分:0)

也许可以尝试添加&#34; keyup&#34;方法太

<?php                   
include('db.php');
session_start();

if (isset($_POST['submit'])){
//$id= $_POST["id"];                                
$email = $_POST['email'];
$pwd = $_POST['pwd'];       

$query = "SELECT * FROM register WHERE email='$email' and pwd='$pwd'";
$result = mysqli_query($connection, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){

$_SESSION['email'] = $email;
header("Location:Employee/dashboard.php"); //here if user successfully log in his user id should be also visible in url bar

}else{

$query = "SELECT * FROM art WHERE email='$email' and pwd='$pwd'";
$result = mysqli_query($connection, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){

$_SESSION['email'] = $email;
header("Location:Recruiter/dashboard.php"); 
}else{

echo "<script>alert('Incorrect user id and password')</script>";
    }
    }
}
?>