开发者

How to save record lists when click save button(PHP and MSQL)

How to save record lists when clic开发者_运维知识库k save button(PHP and MSQL).

Example:

ID Name Sex

1  Jam   m    
2  Da    F    
3  vi    F

When i click save button. i would to save those records to database.

How to do that?

Best regards


Based on your code, This is what you need...

<html>
<head>
<title>Stackoverflow - Serializing Table Data Example</title>
</head>
</body>


<table id='myTable'>
<tr> <th>Name</th> <th>Age</th> </tr>
<tr><td class='name'>william</td><td class='age'>32</td></tr>
<tr><td class='name'>tom</td><td class='age'>25</td></tr>
<tr><td class='name'>sue</td><td class='age'>65</td></tr>
<tr><td class='name'>jeff</td><td class='age'>38</td></tr>
<tr><td class='name'>nancy</td><td class='age'>26</td></tr>
</table>



<input type="button" value="save" id="btnsave" name="btnsave">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<script>
$(document).ready(function(){

    $('#btnsave').click(function(){
        data = '';
        var list = $('#myTable');
        var i = 0;
        list.find('tr').each(function(){
            data += '&name-'+i+'='+$(this).find('.name').html();
            data += '&age-'+i+'='+$(this).find('.age').html();
            i++;
        });
        alert(data);
        /*
        $.post('yourPostPage.php', data, function(returnedData){
            alert(returnedData);
        });
        */
    });
});
</script>
</body>
</html>


<?php
if ($_GET['save']){
   include("mysql_connect.php");
   mysql_query("
   INSERT INTO 
       table 
   VALUES 
       ('1', 'Jam', 'm'), 
       ('2', 'Da', 'F'), 
       ('3', 'vi', 'F');");
  }
  ?>
  <a href="<?php echo $_SERVER['PHP_SELF']; ?>?save=1">SAVE</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜