2016-04-23 45 views
0

如何從HTML表中選擇一些MySQL數據?我如何使用一個HTML更新表單更新所有選定的數據?PHP&Mysql批量選擇數據並使用一種HTML格式更新所有選定的數據

我以爲使用複選框我可以選擇一些數據,但是如何用一個更新表單更新所有選定的數據?

例子:

--- ------------------------ 
id | name | phone| Address| 
---------------------------- 
1 | HSSSS| 57883|  | 
---------------------------- 
2 | BBBBB| 97668|  | 
---------------------------- 
3 | CCCCC| 23454|  | 
---------------------------- 
4 | CCCCC| 23454|  | 
---------------------------- 

你可以看到表中的地址欄沒有數據。現在假設我選擇了2,3,4個號碼data[address]。那麼,如何使用一個HTML更新表單更新所有選定的數據呢?

+2

郵編你的問題,你什麼嘗試。其有用的給你 – JYoThI

+0

想知道答案更新每個選定人員或每個不同地址的相同地址? – JYoThI

+0

是的,我想用html更新表單更新每個選定人員的相同地址,所以我需要php mysql腳本來做到這一點 –

回答

0

將複選框添加到每個表格行是一個好方法。

您需要將此自行解決,但這裏有一些提示:

0

第一種形式應該是這樣的

list.php的

list.php 
 

 
here you select using checkbox whoever you want edit. all the id are stored in user_ids[] array . 
 

 
<form action="update.php" method="post"> 
 
<input type="checkbox" name="user_ids[]" value="1" > 
 
<input type="checkbox" name="user_ids[]" value="2" > 
 
<input type="checkbox" name="user_ids[]" value="3" > 
 
<input type="submit" name="list" value="submit" > 
 
</form> 
 

 

 
then here we received those ids and set into hidden field and fill the address field and submit and your query should be like this . 
 

 
update.php 
 

 
<?php 
 
\t 
 
\t if(isset($_POST['update'])) 
 
\t { 
 
\t \t \t 
 
\t \t \t $ids = implode(',',$_POST['update_user_ids']); 
 
\t \t 
 
\t \t \t //$conn //your connection variable 
 
\t \t \t mysql_query($conn,"update your_table_name set address='".$_POST['address']."' where id IN(".$ids.")"); 
 
\t \t 
 
\t } 
 
\t else 
 
\t { 
 

 
\t \t ?> 
 
\t \t <form action="update.php" method="post"> 
 

 
\t \t <?php foreach($_POST['user_ids'] as $row){ 
 
\t \t \t 
 
\t \t ?> 
 

 
\t \t <input type="hidden" name="update_user_ids[]" value="<?php echo $row; ?>" > 
 

 
\t \t <?php 
 
\t \t \t 
 
\t \t } 
 

 
\t \t ?> 
 
\t \t <textarea name="address" ></textarea> 
 

 
\t \t <input type="submit" name="update" value="submit" > 
 

 

 
\t \t </form> 
 

 
\t <?php \t \t 
 
\t } 
 
\t \t 
 
\t ?> 
 
\t 
 
\t