www.webdeveloper.com
Results 1 to 4 of 4

Thread: Issue with PHP, mysql or ajax?

  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Issue with PHP, mysql or ajax?

    Hello,

    I`m a newbie to javascript and/or ajax and I want to develop an app which takes reports handwriting out of operator duties. Here you have a picture with what I did by now. http://i49.tinypic.com/51593p.jpg
    Behind is a report made in HTML and CSS. When user clicks on a button to add a product, the small form in front appear and he inputs the properties of the current product. When he finish, the app must insert data collected into mysql(i`ve already did it) but my big issue is how to show the properties he already submitted in the main table, to the first column available without refreshing the page. I'm trying to learn about ajax and javascript but I really need to solve that issue fast and thought that you can help with some references, maybe another programming language can help me.

    Thanks in advance for your answers,
    Lilian

  2. #2
    Join Date
    Nov 2010
    Posts
    1,085
    you can collect the data that you are sending to the server and use it to populate the table without refreshing the page using plain javascript. The complicated thing I guess will be knowing which info goes where. You could give all those table cells id's and update their innerHTML using getElementById, but then I guess the question would be what are the other columns for? If it is possible to pull up another form having submitted the first one and fill out details that should go in the second column then you will have to keep track of which column you would like to enter the new info into.

    Either way it is not hard. If you would like to post the html for your form and table and the function that submits the info to the server we can see what is the best way to do it.

  3. #3
    Join Date
    Oct 2012
    Posts
    2
    Hi,

    Thanks for your message.
    I managed to make it work finally with smh like that:

    PHP:
    <?php
    $rz=mysql_query('SELECT * from `bobine`');
    while($row=mysql_fetch_assoc($rz))
    {
    $nr_bob[]=$row['nr_bobina'];
    ...
    }
    $query="select COUNT(*) from `bobine`";
    $count = mysql_fetch_array(mysql_query($query));
    $count = $count[0];
    $var_nr_bob=implode(":#:",$nr_bob);
    //.....
    ?>
    JAVASCRIPT:
    <script>
    function changeContent()
    {
    xnr_bobina=document.getElementById('prod').rows[16].cells;
    ...
    var_nr_bob = "<?php echo $var_nr_bob; ?>";
    array_nr_bob = new Array();
    array_nr_bob = var_nr_bob.split(":#:");
    ...

    for (var i=0;i<<?php echo $count;?>;i++)
    {
    ...
    xnr_bobina[i+1].innerHTML=array_nr_bob[i];
    ...
    }
    </script>

    As I said in my previous post, my add form inserts the record into table and the code above shows all the records from my table. When I click the show button it works, but if I add another record, it won`t work anymore. If I reload the page and click button again it will put in place all the records, including the new-added record. I searched on the web and I found that it may work with AJAX request. I have to put php code to an external file and make AJAX request. Can you help me with this one? I`m stuck.

    Thanks,
    Lilian21

  4. #4
    Join Date
    Nov 2010
    Posts
    1,085
    I don't know what any of that is supposed to do, but maybe this simple example will be of use...
    Code:
    <html>
    <head>
    <style>
    td{width:30%}
    </style>
    
    </head>
    
    <body>
    <form>
    name: <input name="nm"/>
    age: <input name="age"/>
    job: <input name="job"/>
    <input type="button" value="submit" onclick="fillTable(this.form)"/>
    </form>
    <table id="tab" width="75%" border="1">
      <tr>
        <td>Name</td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>Age</td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>Job</td>
        <td></td>
        <td></td>
      </tr>
    </table>
    <script>
    var count=1;
    function fillTable(frm){
    var therows=document.getElementById("tab").rows;
    var vals=[frm.nm.value,frm.age.value,frm.job.value]
    for (var i = 0; i < therows.length; i++) {
    therows[i].cells[count].innerHTML=vals[i]
    	}
    count++
    frm.submit();
    frm.reset();
    	}
    </script>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles