SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery auto suggest

    Hi,

    I am following the following example to create predictive text pull out of the database..

    http://papermashup.com/jquery-php-ajax-autosuggest/

    Seemed quite easy but it seems like it's not working for me, maybe because i'm doing something wrong?

    This is the page:

    http://www.prima.cse.salford.ac.uk:8.../view/test.php

    If you start typing in the big search box the suggestions box appears in the wrong place, and it should be returning some results but it's not.

    This is my autoSuggest.php file:

    PHP Code:
       $db = new mysqli('***''***' ,'****''****');
        
        if(!
    $db) {
        
            echo 
    'Could not connect to the database.';
        } else {
        
            if(isset(
    $_POST['queryString'])) {
                
    $queryString $db->real_escape_string($_POST['queryString']);
                
                if(
    strlen($queryString) >0) {

                    
    $query $db->query("SELECT CPtitle FROM ConfPaper WHERE CPtitle LIKE '$queryString%' LIMIT 10");
                    if(
    $query) {
                    echo 
    '<ul>';
                        while (
    $result $query ->fetch_object()) {
                             echo 
    '<li onClick="fill(\''.addslashes($result->CPtitle).'\');">'.$result->CPtitle.'</li>';
                         }
                    echo 
    '</ul>';
                        
                    } else {
                        echo 
    'OOPS we had a problem :(';
                    }
                } else {
                    
    // do nothing
                
    }
            } else {
                echo 
    'There should be no direct access to this script!';
            }
        } 
    And finally this is the JavaScript:

    PHP Code:
        <script type="text/javascript">
        function 
    suggest(inputString){
                        if(
    inputString.length == 0) {
                                $(
    '#suggestions').fadeOut();
                        } else {
                        $(
    '#documents').addClass('load');
                                $.
    post("includes/autosuggest.php", {queryString""+inputString+""}, function(data){
                                        if(
    data.length >0) {
                                                $(
    '#suggestions').fadeIn();
                                                $(
    '#suggestionsList').html(data);
                                                $(
    '#documents').removeClass('load');
                                        }
                                });
                        }
                }

                function 
    fill(thisValue) {
                        $(
    '#documents').val(thisValue);
                        
    setTimeout("$('#suggestions').fadeOut();"600);
                }
        
    </script> 
    Can you see an obvious problem with what i am doing?

    Thanks
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I managed to get it working, it was a school boy error!

    misspelled a variable

    Thanks
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •