SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Look up

  1. #1
    SitePoint Enthusiast Daniel,D,D's Avatar
    Join Date
    Apr 2009
    Location
    Sandy utah USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Look up

    How do you make a javascript look up???

    I've made one in PHP now I want to make one in javascript
    dose anyone know how to do that?

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of re-posting the same question, could you explain what you're trying to accomplish? If you want to do an SQL lookup via AJAX, you still need the PHP script to do the query and send the results back. If you're using a framework with a database wrapper that has a "fetchAll" method or similar, it's fairly easy. Just execute the query and JSON-encode the resultset.

    In your PHP script:

    Code:
    // Sanitize user input.
    $whatever = $db->quote($_POST['whatever']);
    // This returns an array of objects in Zend framework. Each object has MySQL (or whatever) column names as property names.
    $result = $db->fetchAll('SELECT * FROM my_table WHERE some_col=$whatever");
    echo json_encode($result);
    In your AJAX callback:

    Code:
    var result = eval('(' + request.responseText + ')');
    for (var i=0; i < result.length; i++) {
     for (var prop in result[i]) alert('Column "' + prop + '" = ' + result[i][prop]);
    }

  3. #3
    SitePoint Enthusiast Daniel,D,D's Avatar
    Join Date
    Apr 2009
    Location
    Sandy utah USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's want I want my lookup to be like.
    http://www.gbreman.com/catalog.aspx

  4. #4
    SitePoint Enthusiast Daniel,D,D's Avatar
    Join Date
    Apr 2009
    Location
    Sandy utah USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In fact it's more of a catalog that I want.


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
  •