nangkap Cekbox dinamis

rickeck · Dec 18, 2012
Aku bikin suatu scrip dmna scrip itu terdapat cekbox yang di ulang dengan nama cekboxa yg berbeda,dan di script yg ke dua aku menampilkannya...tp knapa yg muncul hanya value dari cekbox yang paling terakhir...mhon bantuannya.....
index.php
<?php
session_start();
$date=date("Y-m-d");

?>
<!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>Equity Indonesia</title>
<link rel="stylesheet" type="text/css" href="css/accordion_glam.css" />
<link rel="stylesheet" type="text/css" href="css/style3.css" />

<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
</head>
<body>
 <div id="header">
 <div class="shell"><div class="logo"> <img src="images/Logo-Equity.png" align="left" height="95"/></div>
 <div class="right_header"></div>
 </div></div>
<br />

<div id="main_container">
  <div class="main_content">
    
                   <br />  <br /> 
      <div class="center_content">
        <div class="right_content">
        
        
        <?php 
		include "main_function.php";
		$sqlpesan = mysql_query("select * from tb_pesan");
		$no = mysql_num_rows($sqlpesan);
		?>
        <table width="1057" id="rounded-corner-notgl">
        <tr>
          <td width="28" height="33" align="left" valign="middle"><h2>No </h2></td>
          <td width="10" align="right" valign="middle"><h2>: </h2></td>
          <td width="375" align="left" valign="middle"><h2><?php echo $no+1; ?> </h2></td>
          <td width="2" valign="middle">&nbsp;</td>
          <td width="583" align="right" valign="middle"><h2>Tanggal </h2> </td>
          <td width="10" align="right" valign="middle"><h2>: </h2></td>
          <td width="17" align="left" valign="middle"><h2><?php echo $date; ?> </h2></td>
        </table>
        
        <?php
		
		include "main_function_formbec.php";
		$sqlmember = mysql_query("select * from tb_member where ID_member = '".$_SESSION['ID_member']."'");
		$member = mysql_fetch_array($sqlmember);
		?>
          <table width="850px" height="49" id="rounded-corner-top">
            <thead>
              <tr>
              <th width="850" height="16" align="center" valign="top">
              <table width="476"  id="rounded-corner">
                <tr>
                  <th width="123">Member ID</td>
                  <th width="19" align="left">:</td>
                  <td width="318"><?php echo $_SESSION['ID_member']; ?></td>
                </tr>
                <tr>
                  <th>Member
                  <th align="left">:
                    </th>
                  <td><?php echo $member['nama_member']; ?></td>
                </tr>
              </table></th>
              <th align="center" valign="top"><table  id="rounded-corner">
                <tr>
                  <th width="99">No Tlpn
                  <th width="26" align="left">:</td>
                  <td width="284"><?php echo $member['notlpn']; ?></td>
                </tr>
                <tr>
                  <th>Alamat
                  <th align="left">:
                    </td>
                  <td><?php echo $member['alamat']; ?></td>
                </tr>
                
              </table></th>
            </tr></thead>
            <tbody></tbody>
          </table>
          <br />
          <?php 
include "main_function.php";
?>
          <form name="filter" action="?" method="get"><table id="rounded-corner-top" width="1057">
            <tr>
          <td width="35">Pusat</td>
          <td width="2">:</td>
          <td width="180"><input type="text" name="pusat" value="<?php if (isset($_GET['pusat'])){ echo $_GET['pusat']; }else{} ?>"/></td>
          <td width="66">Cabang</td>
          <td width="2">:</td>
          <td width="185"><input type="text" name="cabang" value="<?php if (isset($_GET['cabang'])){ echo $_GET['cabang']; }else{} ?>" /></td>
       	  <td width="81">Distributor</td>
       	  <td width="8">:</td>
       	  <td width="178"><input type="text" name="distributor" value="<?php if (isset($_GET['distributor'])){ echo $_GET['distributor']; }else{} ?>" /></td>
          <td width="77"><input type="submit" value="Filter" /></td>
          </tr></table></form>
         <br />
          <table width="1057" height="8" bgcolor="#666666">
          <tr><td width="1053" height="2"></td>
          </tr></table>
          <br />
          <a href="?all=yes">Load..</a>
          <form action="proses.php" name="usertest" method="post">
          <table width="1057" id="rounded-corner-buttom">
            <tr>
              <th width="41" align="center" valign="middle">Pilih</th>
          <th width="216">Test ID</th>
          <th width="180">Nama</th>
          <th width="31" align="center" valign="middle">JK</th>
          <th width="205">No Tlpn</th>
          <th width="257">Alamat</th>
          <th width="95" align="center" valign="middle">Tanggal Test</th>
          </tr>
          <?php
		  $pusat = $_GET['pusat'];
		  $cabang = $_GET['cabang'];
		  $distributor = $_GET['distributor'];
		  
		  if(isset($_GET['pusat']) || isset($_GET['cabang']) || isset($_GET['distributor']))
		  {
		  $i=1;
		  $sql = mysql_query("select * from tb_usertest  where  pusat = '".$pusat."' and cabang = '".$cabang."' and distributor = '".$distributor."' order by tgl_test DESC");
		  while($data = mysql_fetch_array($sql))
		  {
          ?><tr>
            <td align="center" valign="middle"><input type="checkbox" name="A<?php echo $data['ID_test']; ?>" value="<?php echo $data['ID_test']; ?>" /></td>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr><?php 
		  $i++;
		  ?><input type="hidden" name="n" value="<?php echo $i; ?>"/>
          <input type="hidden" name="ID_test" value="<?php echo $data['ID_test']; ?>"/>
		  <?php
		  } 
		  
		  }
		  else
		  {
		  $i=1;
		  $sql = mysql_query("select * from tb_usertest order by tgl_test DESC");
		  while($data = mysql_fetch_array($sql))
		  {
          ?><tr>
            <td align="center" valign="middle"><input type="checkbox" name="A<?php echo $data['ID_test']; ?>"  value="<?php echo $data['ID_test']; ?>"/></td>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr><?php 
		  $i++;
		  ?>
          <input type="hidden" name="n" value="<?php echo $i; ?>"/>
          <input type="hidden" name="ID_test" value="<?php echo $data['ID_test']; ?>"/>
		  
		  
		  <?php
		  } 
		  
		  }
		  ?></table>
          
          <input name="ok" type="submit" value="OK" class="buttonbt_blue">
          </form>
          <h2></h2>
     </div>
    <!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
</div> <!--end of main content-->
	
    
  <div class="footer"></div>
</div>		
</body>

<br />
</html>
proses.php

<?php
session_start();

include "main_function.php";

//$nmcb = "A".$_POST["ID_test"];
$n= $_POST['n'];


$date=date("Y-m-d");


?>
<!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>Equity Indonesia</title>
<link rel="stylesheet" type="text/css" href="css/accordion_glam.css" />
<link rel="stylesheet" type="text/css" href="css/style3.css" />

<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
</head>
<body>
 <div id="header">
 <div class="shell"><div class="logo"> <img src="images/Logo-Equity.png" align="left" height="95"/></div>
 <div class="right_header"></div>
 </div></div>
<br />

<div id="main_container">
  <div class="main_content">
    
                   <br />  <br /> 
      <div class="center_content">
        <div class="right_content">
          <form action="proses.php" name="usertest" method="post">
          <table width="1057" id="rounded-corner-buttom">
            <tr>
          <th width="216">Test ID</th>
          <th width="180">Nama</th>
          <th width="31" align="center" valign="middle">JK</th>
          <th width="205">No Tlpn</th>
          <th width="257">Alamat</th>
          <th width="95" align="center" valign="middle">Tanggal Test</th>
          </tr>
          <?php
		  $nmcb = "A".$_POST['ID_test'];
		  $ID = $_POST[$nmcb];
		   $sql = mysql_query("select * from tb_usertest where ID_test = '".$ID."' order by tgl_test DESC");
		  while($data = mysql_fetch_array($sql))
		  {
          ?><tr>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr><?php 
		  }
		  ?></table>
          
          </form>
          <h2></h2>
     </div>
    <!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
</div> <!--end of main content-->
	
    
  <div class="footer"></div>
</div>		
</body>

<br />
</html>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Dec 18, 2012 · 0 Suka · 0 Tidak Suka
saya sarankan untuk menggunakan penamaan input seperti ini:
<input type="text" name="A[0]"/>
<input type="text" name="A[1]"/>
<input type="text" name="A[2]"/>
<input type="text" name="foo[X]"/>
<input type="text" name="foo[W]"/>
<input type="text" name="foo[Z]"/>
sehingga pada saat form disubmit maka di php nilainya akan seperti:
$_POST = array(
	'A' => array(
		0 => '',
		1 => '',
		2 => ''
	)
	'foo' = array(
		'X' => '',
		'W' => '',
		'Z' => ''
	)
)
jadi penanganan datanya lebih mudah, tinggal lakukan iterasi.

<?php
		  $pusat = $_GET['pusat'];
		  $cabang = $_GET['cabang'];
		  $distributor = $_GET['distributor'];
 
		  if(isset($_GET['pusat']) || isset($_GET['cabang']) || isset($_GET['distributor']))
		  {
		  $sql = mysql_query("select * from tb_usertest  where  pusat = '".$pusat."' and cabang = '".$cabang."' and distributor = '".$distributor."' order by tgl_test DESC");
		  while($data = mysql_fetch_array($sql))
		  {
          ?><tr>
            <td align="center" valign="middle"><input type="checkbox" name="A[<?php echo $data['ID_test']; ?>]" value="<?php echo $data['ID_test']; ?>" /></td>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr>
		  <?php
		  } 
 
		  }
		  else
		  {
		  
		  $sql = mysql_query("select * from tb_usertest order by tgl_test DESC");
		  while($data = mysql_fetch_array($sql))
		  {
          ?><tr>
            <td align="center" valign="middle"><input type="checkbox" name="A[<?php echo $data['ID_test']; ?>]"  value="<?php echo $data['ID_test']; ?>"/></td>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr><?php 
		  ?>
		  <?php
		  } 
 
		  }
		  ?></table>

proses.php
	<?php
	foreach($_POST['A'] as $ID){
	   $sql = mysql_query("select * from tb_usertest where ID_test = '".$ID."' order by tgl_test DESC");
	  while($data = mysql_fetch_array($sql))
	  {
          ?><tr>
            <td align="left" valign="middle"><?php echo $data['ID_test']; ?></td>
           <td align="left" valign="middle"><?php echo $data['nama']; ?></td>
            <td align="center" valign="middle"><?php echo $data['jenis_kelamin']; ?></td> 
            <td align="left" valign="middle"><?php echo $data['notlpn']; ?></td> 
          <td align="left" valign="middle"><?php echo $data['alamat']; ?></td>
            <td align="center" valign="middle"><?php echo $data['tgl_test']; ?></td>
          </tr>
          <?php }?>
          <?php }?>