在jquery中没有显示mysql的结果细节

时间:2017-08-20 08:04:49

标签: jquery mysql

以下代码为html代码:

<input type="search" name="srchtxt" id="srchtxt"/>
<div class="resultsearch">
    <ul class="ul"></ul>
</div>
<a href="#" id="srchbtn"></a>

以下代码为jquery代码:

$("#srchtxt").keyup(function(){
    var addresshome = $("#srchtxt").val();
    $.post("addressfile",{address:addresshome},function(res){
        $(".ul").html(res);
    });
});
$(".ul li#item a").each(function(){
    $(this).click(function(e){
        e.preventDefault();
        var index_address,address;
        index_address = $(this).parent().index();
        alert(index_address);
        address = $(this).eq(index_address).attr("value");
        $("#srchtxt").attr("value",address);
    });
});
$("#srchbtn").click(function(){
    alert($("#srchtxt").val());
});

以下代码为php代码:

$address = $_POST['address'];$querysrch = "select city,state,bolv from table where city like '%".$address."%' or state like '%".$address."%' or bolv like '%".$address."%'";$ressrch = mysqli_query($cnt,$querysrch);if(mysqli_num_rows($ressrch) > 0){
while($row = mysqli_fetch_assoc($ressrch)){
    $addressres = $row['city']."-".$row['state']."-".$row['bolv'];
    echo "<li id='item'><a href='#' value='".$addressres."'>".$addressres."</a></>";
}}else{    echo "<li id='item'><a href='#' value='not found'>notfound</a></li>";}

当结果显示时,我无法访问显示值的li列表或插入到id =&#34; srchtxt&#34;

1 个答案:

答案 0 :(得分:1)

试试这段代码:

$results = '';
$address = $_POST['address'];
$querysrch = "select city,state,bolv from table where city like '%".$address."%' or state like '%".$address."%' or bolv like '%".$address."%'";
$ressrch = mysqli_query($cnt,$querysrch);
if(mysqli_num_rows($ressrch) > 0){
    while($row = mysqli_fetch_assoc($ressrch)){
        $addressres = $row['city']."-".$row['state']."-".$row['bolv'];
        $results .= "<li id='item'><a href='#' value='".$addressres."'>".$addressres."</a></li>";
    }
}
else
{ 
    $results .= "<li id='item'><a href='#' value='not found'>notfound</a></li>";
}
echo $results;
return;