|
 |
|
ใครมีวิธีให้ insert เฉพาะ record แถวเดียว ใน หลาย record ได้บ้างครับ |
|
 |
|
|
 |
 |
|
น่าจะประมาณนี้ครับ ลองเอาไปปรับเอานะครับ
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
#แสดงค่าที่ส่งมาจากฟอร์ม
if($_POST){
echo "<pre>";
print_r($_POST);
echo "</pre>";
#ต่อไปก็เป็นส่วนของการ INSERT , UPDATE ลงฐานข้อมูล
#........SQL Code......
}
?>
<table width="260" border="1">
<tr>
<td width="144">ข้อมูล</td>
<td width="100"> </td>
</tr>
<?PHP for($i=0;$i<=10;$i++) { ?>
<form id="form1" name="form1" method="post" action="">
<tr>
<td>
<input name="textfield" type="text" id="textfield" value="ข้อมูลที่ <?=$i;?>" />
</td>
<td>
<input type="submit" name="button" id="button" value="Submit" />
<!--hidden นี้ใช้เช็คว่าเราส่งข้อมูลแถวไหนไปครับ-->
<input name="row" type="hidden" id="hiddenField" value="<?=$i;?>" />
</td>
</tr>
</form>
<?PHP } ?>
</table>
</body>
</html>
|
 |
 |
 |
 |
Date :
2013-07-11 08:40:24 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันเก็บไปทุกฟิล์เลยครับใช้ $_REQUEST['row']; ปรากฏว่ามันยังเอาแถวสุดท้ายมาครับ
|
 |
 |
 |
 |
Date :
2013-07-12 07:23:12 |
By :
Nos1001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณเขียนโค้ดไว้ยังไงครับ เอาโค้ดมาดูครับ
|
 |
 |
 |
 |
Date :
2013-07-12 09:10:57 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
view
Code (PHP)
<form name="receive" method="POST" action="<?php echo site_url('phone/receive'); ?>" >
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Name - Lastname</th>
<th>Mobile</th>
<th>Remark</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$a=1;
foreach($new as $receive):
<tr>
<td>
<?PHP
foreach($member as $receive_member):
?>
<td class="center"><?php echo iconv('tis-620','utf-8',$receive_member->user_fname)." ".iconv('tis-620','utf-8',$receive_member->user_lname); ?>
</td>
<?PHP
endforeach;
?>
<td class="center">
<?PHP
foreach($phone as $receive_phones):
?>
<input type="hidden" value="<?=$receive_phones->id;?>" name="id_phone">
<?PHP
endforeach;
?>
</td>
<td>
<input type="text" name="remark<?=$a;?>" size="50" maxlength="250" >
</td>
<td class="center">
<button type="submit" class="btn btn-primary" name="enter_receive<?=$a;?>" value="Receive">Receive</button>
<input name="row" type="text" id="hiddenField" value="<?=$a;?>" />
</td>
</tr>
<?php
$a++;
endforeach;
?>
</tbody>
</table>
</form>
controller (มันออก row สุดท้ายครับ ไม่ว่าจะกด submit ตรงแถวไหนก็แล้วแต่)
Code (PHP)
public function receive()
{
echo $_REQUEST['row']."<br>";
}
|
ประวัติการแก้ไข 2013-07-13 13:51:01 2013-07-13 13:51:23
 |
 |
 |
 |
Date :
2013-07-13 13:12:02 |
By :
Nos1001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สาเหตุที่ออกแต่ Row สุดท้าย เพราะคุณครอบ <form> ทั้งหมด ลองดูตัวอย่างของผมที่ให้ไปก่อนหน้านี้ แล้วลองดูของคุณว่ามันต่างกันตรงไหน?
ส่วนโค้ดข้างล่างผมแก้ให้ตามความน่าจะเป็น ลองดูครับ
Code (PHP)
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Name - Lastname</th>
<th>Mobile</th>
<th>Remark</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$a=1;
foreach($new as $receive): ?>
<form name="receive" method="POST" action="<?php echo site_url('phone/receive'); ?>" >
<tr>
<td>
<?PHP
foreach($member as $receive_member):
?>
<td class="center"><?php echo iconv('tis-620','utf-8',$receive_member->user_fname)." ".iconv('tis-620','utf-8',$receive_member->user_lname); ?>
</td>
<?PHP
endforeach;
?>
<td class="center">
<?PHP
foreach($phone as $receive_phones):
?>
<input type="hidden" value="<?=$receive_phones->id;?>" name="id_phone">
<?PHP
endforeach;
?>
</td>
<td>
<input type="text" name="remark<?=$a;?>" size="50" maxlength="250" >
</td>
<td class="center">
<button type="submit" class="btn btn-primary" name="enter_receive<?=$a;?>" value="Receive">Receive</button>
<input name="row" type="text" id="hiddenField" value="<?=$a;?>" />
</td>
</tr>
</form>
<?php
$a++;
endforeach;
?>
</tbody>
</table>
|
ประวัติการแก้ไข 2013-07-13 15:07:24
 |
 |
 |
 |
Date :
2013-07-13 15:04:04 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
555+ ทำตามแล้วครับ กดไม่ไป
|
 |
 |
 |
 |
Date :
2013-07-13 15:44:07 |
By :
Nos1001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|