doumo1807831 2014-04-01 08:39
浏览 22
已采纳

显示包含在文本框中键入的句子的结果

Hello I want to make a textbox that can select data from a table, when input is givin to the textbox it should autocomplete the sentance with any words it matches within the

I already have this piece of code and it works but it only shows result of the first symbol you type in.

function lookup(inputString)
{
    if(inputString.length == 0)
    {
        $('#suggestions').hide();
    }    
    else     
    {    
        $.post("sql_naam_klant.php", {queryString: ""+inputString+""}, function(data)    
        {   
    if(data.length >0)    
    {    
        $('#suggestions').show();    
        $('#autoSuggestionsList').html(data);
    }
        });
    }
}

function fill(thisValue) 
{
    $('.inputString').val(thisValue);
    setTimeout("$('.suggestions').hide();", 200);
}

HTML:

<input type="text" name="naam_klant" size="20" id="naam_klant" onkeyup="lookup(this.value);" onblur="fill();" >    
            <div class="suggestionsBox" id="suggestions" style="display: none;">
            <div class="suggestionList" id="autoSuggestionsList">

UPDATE:

<?php
$db = new mysqli('localhost', 'root' ,'*', 'records');
if(!$db) 
{
// Show error if we cannot connect.        
echo 'ERROR: Could not connect to the database.';
} 

else 
{
// Is there a posted query string?
if(isset($_POST['queryString']))
{
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) 
{
$query = $db->query("SELECT naam_klant FROM overboekingen WHERE naam_klant LIKE '$queryString%' LIMIT 10");     

if($query)
{
while ($result = $query ->fetch_object())
{
echo '<li onClick="fill(\''.$result->naam_klant.'\');">'.$result->naam_klant.'</li>';
}
}

else 
{
echo 'ERROR: There was a problem with the query.';
}
} 
else 
{
} // There is a queryString.
} 
else 
{
echo 'There should be no direct access to this naam_klant script!';
}   
}
?>
  • 写回答

2条回答 默认 最新

  • dongmin3754 2014-04-01 08:51
    关注

    I can't answer the question because it is incomplete. We need to see the content of the sql_naam_klant.php to see why is it like that.

    I am assuming that the error is in the query.

    Use the Wildcard Symbol (%) in your where statements.

    "Select * from tblnames where name like '%$queryString%';"
    

    Will edit this answer as soon as you provide us with complete details.

    If you want to find what you typed inside,beginning or end of a text block use the wildcard in both start and end of the search keyword. %$queryString%. If what you are looking for is the in beginning of a block of text then use $queryString% and if you're looking at the end of a text blook %$queryString.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题