|
 |
|
สอบถามปัญหาในการ รับค่าจาก checkbox มีตัวอย่างครับว่าให้รับอย่างไร |
|
 |
|
|
 |
 |
|
1. คือผมจะเก็บ ลง database อย่างไร เมื่อ มีให้เลือก เพียง 2 ตัวเลือก ตามรูปครับ แล้วมีทั้งหมด 28 ข้อ
2. จะกำหนดตรง name="option[]" id="option_1" value="<?php echo $row['chooseM1']?>" อย่างไรครับ

Code (PHP)
////////////////// ตัวที่เก็บ array (มี28 array )
$table = array(
array('num'=>'1','question1'=>'กระตือรือร้น', 'question2'=>'กล้า', 'question3'=>'พิธีการ', 'question4'=>'พอใจ',
'chooseM1'=>'M1','chooseL1'=>'L1','chooseM2'=>'M2','chooseL2'=>'L2','chooseM3'=>'M3','chooseL3'=>'L3','chooseM4'=>'M4','chooseL4'=>'L4'),
array('num'=>'2','question1'=>'ระมัดระวัง', 'question2'=>'แน่วแน่', 'question3'=>'จูงใจ', 'question4'=>'มนุษยสัมพันธ์ดี',
'chooseM1'=>'M21','chooseL1'=>'L21','chooseM2'=>'M22','chooseL2'=>'L22','chooseM3'=>'M23','chooseL3'=>'L23','chooseM4'=>'M24','chooseL4'=>'L24'),
//////////////// ผมใช้ array ในการทำ table ซึ่ง แต่ละ value จะมีค่าของมันเองเฉพาะ
<?php while (list(,$row) = each($table)): ?>
<tr>
<th><?php echo $row['num'];?></th>
<th>มาก</th>
<th>น้อย</th>
</tr>
<tr>
<td><?php echo $row['question1'];?></td>
<td><input type="checkbox" name="option[]" id="option_1" value="<?php echo $row['chooseM1']?>" /></td>
<td><input type="checkbox" name="option[]" id="option_2" value="<?php echo $row['chooseL1']?>" /></td>
</tr>
<tr>
<td><?php echo $row['question2'];?></td>
<td><input type="checkbox" name="option[]" id="option_3" value="<?php echo $row['chooseM2']?>" /></td>
<td><input type="checkbox" name="option[]" id="option_4" value="<?php echo $row['chooseL2']?>" /></td>
</tr>
<tr>
<td><?php echo $row['question3'];?></td>
<td><input type="checkbox" name="option[]" id="option_5" value="<?php echo $row['chooseM3']?>" /></td>
<td><input type="checkbox" name="option[]" id="option_6" value="<?php echo $row['chooseL3']?>" /></td>
</tr>
<tr>
<td><?php echo $row['question4'];?></td>
<td><input type="checkbox" name="option[]" id="option_7" value="<?php echo $row['chooseM4']?>" /></td>
<td><input type="checkbox" name="option[]" id="option_8" value="<?php echo $row['chooseL4']?>" /></td>
</tr>
<?php endwhile; ?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-04-24 22:28:46 |
By :
kitithat |
View :
2617 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ใช้ array ไม่ได้น่ะครับ ให้ระบุ id หรือ name เป็นลำดับของแถวครับ และอีกอย่างควรใช้ radio button หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-04-25 06:26:09 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
-ขอบคุณครับ พี่ วินมากครับ ติดตามๆตลอดๆ 
1. ถ้าวิธี checkbox คือ ไม่มีวิธีไหนเลยใช่หรือป่าวครับ
// ดังนั้นควรให้ผม ใช้แบบ radio button พอมีตัวอย่างให้ผม insert เข้า database ไหม๊ครับ
2 . แล้วควรใช้ name=" " ของ radio button คืออะไรครับ
3. ถ้าเค้าไม่เลือกช่องอื่น ให้เป็นค่าว่างดีไหม? เพราะผมต้องดึงข้อมูลจากที่เลือก ไปแล้วนั้น ขึ้นมาใ้ช้งานต่อครับ
|
 |
 |
 |
 |
Date :
2012-04-25 07:36:57 |
By :
kitithat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|