HELP! Urgent. Using JS to retrieve data from DB = mission impossible?

Discussion in 'Javascript' started by ggk517, Mar 2, 2006.

  1. ggk517

    ggk517 Guest

    We are trying to develop an Engineering application using PHP,
    Javascript with Informix as the back-end.

    Is it possible to retrieve data using Javascript but by accessing the
    Database. Say somebody enters part_no, than using Javascript is it
    possible to connect to the part master and retrieve the division and
    desc information?

    I am not allowed to use the PHP because this will require the user to
    insert the part number on the first page (user input page) and then
    retrieve the information using PHP and display the info on the second
    page (processing page).

    I will need this to be done on the same page. That means the info will
    need to be retrieved instantly (on the fly).

    I think of building a javascript array for the part master table using
    PHP but finally decided not to as the table is a huge table (contains
    more than 1000000 records).

    Thanks in advance for your kindness help.
    ggk517, Mar 2, 2006
    1. Advertisements

  2. ggk517

    ggk517 Guest

    Hi, Ian. Thanks for suggestion. Can you please recommend to me any good
    tutorial about AJAX?
    ggk517, Mar 2, 2006
    1. Advertisements

  3. In my amateur opinion, yes. For instance, using the HTTPRequest object
    (one of the methods used in AJAX).
    You may still need to use PHP or some other intermediary, unless you
    are prepared to open your database to remote access (a security issue).
    But this does not necessarily involve a change of page.

    Effectively the HTTPRequest object will make a request from your client
    web page to a PHP web page, which in turn will connect to the database,
    extract data, and send this back to the HTTPRequest object. JavaScript
    can then collect the information from the HTTPRequest object, and
    dynamically update the same page.
    See above.
    A new book on AJAX, is "Professional Ajax" - see


    Julian Turner
    Julian Turner, Mar 2, 2006
  4. ggk517

    jshanman Guest

    AJAX is not the only method. It is also possible to use a script like
    this, that accomplishes the same thing.

    function GetPartNum(part_num) {
    var jsel = document.createElement('SCRIPT');
    jsel.type = 'text/javascript';
    jsel.src = "somepage.php?part_num="+part_num;
    document.body.appendChild (jsel);

    function GotNewData(desc,division) {

    alert("Desc: "+desc+"Division: "+division);


    And the php file can look like this:


    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    $p = $_GET{'part_num'};#may want to do something to avoid injection...

    #db connect
    #db select database
    #run query
    #store escaped results in $desc & $div

    #output results as a javascript function
    echo "GotNewData(\"".$desc."\",\"".$div."\");";


    Now when this is appended, the function is run with the desired
    partnumber. This is more compatible then the XMLHttpRequest Object.

    There is no speed difference either, they both load as fast as the
    server generates the file and how large the content is. Example of both
    methods on a timer:

    - JS
    jshanman, Mar 2, 2006
  5. ggk517

    ggk517 Guest

    Thank you very much to Ian, Julian and JS for your valuable advice. I
    will need some time to digest the information and also the recommended
    methods. I am quite relief now as this problem is actually solvable and
    is not a "mission impossible". Lastly, thanks again and take care.
    ggk517, Mar 5, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.