Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL via PHP and JavaScript

    Question: populating on the fly created select boxes through PHP by retrieving data stored in MySQL tables is essentially a three line piece of code. Now... .Can someone suggest a way to connect the data to select boxes already in the document ?.Thanks in advance...

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: MySQL via PHP and JavaScript

    I'm not sure what you're asking. You want to post back to the server, or you want to add data to the page using JavaScript without going reloading the entire page, or ???

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MySQL via PHP and JavaScript

    I want to return data back to the server. The select boxes are part of a form. Once the boxes have been populated, data is locally processed via JS and then saved back to the server. Once I apply the mysql_fetch_array function and have access to all the members of each and every row....how do I transfer this info to the -existing- boxes so I can operate with the data?.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: MySQL via PHP and JavaScript

    I still might not have the complete picture, but... if "the -existing- boxes" refers to your <select> elements, you can use JavaScript to change them in either of two ways. The simpler is to remove all the <option> nodes from the <select> and add new nodes from your array; the more complicated would be to loop through and insert/delete based on a comparison with your array. Does this seem as though it is heading in the right direction?

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Location
    Detroit, Michigan, USA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MySQL via PHP and JavaScript

    Correct. The simple option is the one I am pursuing but...the question is how do I connect the nodes of the array (that I managed to get through PHP) to the options of the select boxes that are part of the html page. The most universal DOM compliant approach is document.getElementById("selectName').options...bu t this is accessible through JavaScript only..therefore....how do I turn the elements of the array that are floating in cyberspace into options on the select boxes ?. Thanks again in advance.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: MySQL via PHP and JavaScript

    <P ID="edit" class=small>(Edited by jscher2000 on 02-Mar-07 11:07. )</P>I have been assuming you have the page on the client side and want to update locally using JavaScript. However, your post has me confused.

    * I don't think PHP is relevant on the client side. If you have an array it needs to be a JavaScript data structure, regardless of the type of server-side page that returned the array and regardless of the technology used to fetch it. (Added: This looks like a handy source example for the DOM methods: http://www.mredkj.com/tutorials/tutorial005.html.)

    * If you are referring to the page on the server that you are processing before returning it to the client (postback to self) then just use the ordinary PHP syntax to create options from scratch. There is no DOM to manipulate in PHP script, only when the page is in the browser.

Posting Permissions

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