autocomplete shows all entries, Does not do any searching

后端 未结 2 1487
暖寄归人
暖寄归人 2021-01-29 13:51

Please help me ... I\'m a newbie! Please tell me what to do.

processed.php



        
2条回答
  •  野的像风
    2021-01-29 14:34

    That autocomplete function is probably passing a few variables to your processed.php page.

    Use var_dump($_GET) to see all the things you're being passed.

    Inside one of those $_GET elements, you'll have the contents of the text box as they exist on the page. For the sake of demonstration, I'm going to use $_GET['text']. You'll need to find out which part holds the data you need.

    What you'll need to do is search the database using this value for a list of results to return.

    $sql="SELECT name FROM artist";
    $artist = select($sql);
    

    This is your script as it exists. What it may end up looking similar to is this.

    $text_input = mysql_escape_string($_GET['text']);
    $sql="SELECT name FROM artists WHERE name LIKE '%$text_input%'";
    $artist = select($sql);
    

    You'll want to get results that are similar to the inputted text on the user-facing page.

    A few notes for you

    1. I used mysql_escape_string() solely to may what you already have. While this does work (driving around a busted-ass chevy pacer works too, but there are much better ways though), its not recommended, which sets us up for point 2.

    2. Using the old mysql extension is not really a good idea, its been replaced by mysqli, and PDO.

    3. you'll need to escape your data, this is how its done with mysqli.

提交回复
热议问题