SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery UI Autocomplete not working at all!

    So I am trying to impletemt a jQuery Autocomplete that pulls information from a MySQL database using PHP, and it doesn't seem to be working at all! When I type a name into the field that I know is in the database, it doesn't pull up anything. I echoed the PHP code to make sure that it was pulling information from the database, and it was, so I know that works. Here is my HTML:

    HTML Code:
    <div class="search">
    	<form method="post" action="#">
    		<div class="left"><label for="quick-search">Quicksearch</label><input type="text" name="quick-search" id="quick-search" /></div>
    		<div class="button"><input type="submit" name="submit" value="Search" /></div>
    	</form>
    </div>
    Here is my PHP (file - people-autocomplete.php);
    PHP Code:
    $people = array();
        
    global 
    $mysqli;

    if (
    $stmt $mysqli->prepare("SELECT first_name, last_name FROM people")) {

            
    $stmt->execute();
        
    $stmt->bind_result($first_name$last_name);
        
    $i 0;
        while (
    $stmt->fetch()) {
                
    $people[] = $last_name ', ' $first_name;
                ++
    $i;
        }
            
    $stmt->close();
            
        }    
        
        echo 
    json_encode($people); 
    And here is the Javascript I put in the head of the HTML:
    Code:
    <script type="text/javascript">
    	$(document).ready(function() {
    		$("input#quick-search").autocomplete({
    			source: "/manager/model/people-autocomplete.php",
    			minLength: 1,
    		});
    	});
    </script>
    Any ideas?
    James Web Development | New York, NY
    Design, Develop, Deliver

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Do you have a working example of this page as it would be easier to debug it if we had access to it, also what auto complete plugin are you using?
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    No working version, but here is the HTML for the entire page:

    PHP Code:
    <?php 
        session_start
    ();
        
    $compare_id session_id();
        if (
    $compare_id !== $_SESSION['id']) {
            
    header("Location: /logout.php");
        }
        if (isset(
    $_SESSION['per_people']) && $_SESSION['per_people'] == 0) {
            
    header("Location: /manager/index.php");
        }
        
    $inactive 600;
        if (isset(
    $_SESSION["timeout"])) {
            
    $sessionTTL time() - $_SESSION["timeout"];
            if (
    $sessionTTL $inactive) {
                
    session_destroy();
                
    header("Location: /logout.php");
            }
        }
        
    $_SESSION["timeout"] = time();
        
        
    $title 'The Board'
        
    $section 'People';
    ?>

    <?php 
        
    include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/includes/head.php");
        
    /*
        include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/controller/people.php");
        */
        
    include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/view/people.php");
    ?>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#quick-search").autocomplete({
                source: "model/people-autocomplete.php",
                minLength: 1
            });
        });
    </script>

    </head>

    <body>

    <div class="wrap">
        <?php include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/includes/header.php"); ?>
        <?php include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/includes/nav.php"); ?>
        <article>
            <h2>People</h2>
            <?php 
                
    if (isset($_POST['cancel'])) {
                    
    $people = new People_forms;
                    echo 
    $people->People_home();
                } else if (isset(
    $_POST['add'])) {
                    
    $people = new People_forms;
                    echo 
    $people->People_add_family();
                
    /*
                } else if (isset($_POST['task']) && $_POST['task'] == 'addconfirm') {
                    $users = new Users_controller;
                    echo $users->Add_user_confirm();
                } else if (isset($_GET['task']) && $_GET['task'] == 'edit') {
                    $users = new Users_controller;
                    echo $users->Edit_user();
                } else if (isset($_POST['task']) && $_POST['task'] == 'editconfirm') {
                    var_dump($_SESSION);
                    $users = new Users_controller;
                    echo $users->Edit_user_confirm();
                } else if ((isset($_GET['task']) && $_GET['task'] == 'delete') || (isset($_POST['task']) && $_POST['task'] == 'delete')) {
                    $users = new Users_controller;
                    echo $users->Delete_users();
                } else if (isset($_POST['task']) && $_POST['task'] == 'deleteconfirm') {
                    $users = new Users_controller;
                    echo $users->Delete_user_confirm(); 
                */
                
    } else {
                    
    $people = new People_forms;
                    echo 
    $people->People_home();
                }
            
    ?>
        </article>
        <?php include_once ($_SERVER['DOCUMENT_ROOT'] . "/manager/includes/footer.php"); ?>
    </div> <!-- END: .wrap -->

    </body>

    </html>
    James Web Development | New York, NY
    Design, Develop, Deliver

  4. #4
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, the PHP file returns a result like this:

    ["Horbal, Barry","Harriott, Jaclyn"]
    James Web Development | New York, NY
    Design, Develop, Deliver


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
  •