2011-09-08 66 views

回答

1

基於您的代碼,這是你需要什麼...

<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> 
1
<?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

如何從名單表中的數據?它不會被靜態插入。我的意思是循環插入數據庫。 – user872148

相關問題