2015-07-01 46 views
2

嗨,這裏有一個項目列表。過濾字段以生成報告。陣列定位生成報告php

<form action="" method="post"> 
<?php 

    if (isset($_POST['report'])){ 

     if(empty($_POST['check_list'])){ 
      echo "Please select field!<br/>";  
     } 

     if(!empty($_POST['check_list'])){ 

     $id= array_reverse($_POST['check_list']); 
     print_r($id); 
     foreach($id as $key => $report_id){ 
      $s = $report_id . ',' . $s; 
     } 

      //echo $s; 
     $xfields = substr($s, 0, strlen - 1); 
     echo $xfields . ' was/were checked! <br/>'; 

     $x = substr_count($xfields, ','); 

     echo '<table width=100% border=1>'; 
     echo '<tr>'; 
      $field_list = explode(',', $xfields); 
      for ($i = 0; $i <= $x; $i++) 
      { 

       echo '<th>' . $field_list[$i] . '</th>'; 
      } 


     echo '</tr>'; 
     $sql = 'select ' . $xfields . ' from areentry WHERE TagId = 1' ; 
     //echo $sql; 
     $rst = mysql_query($sql); 
     if (!$rst) { 
      echo 'Could not run query: ' . mysql_error(); 
      exit; 
     } 

     if (mysql_num_rows($rst) > 0) { 

      while($xrow = mysql_fetch_array($rst)) { 
       echo '<tr>'; 
       for ($i = 0; $i <= $x; $i++) 
       { 
        echo '<td>' . $xrow[$i] . '</td>'; 
       } 

      } 
       echo '</tr>'; 
     } 

     echo '</table>'; 

     return; 
     } 

    } 

    if (mysql_num_rows($result) > 0) { 
    echo '<table border=1>';   
    echo '<ul>'.NL; 
     while($row = mysql_fetch_array($result)): 
     echo '<tr><td><input type=checkbox name=check_list[] value=' . $row[0] . '>' . $row[0] . '</td></tr>'; 
     endwhile; 
    echo '</table>'; 
    } 
    ?> 

複選框的選擇看起來是這樣,選擇欄後,它產生其中有兩個具有場報告檢查

enter image description here

如何確定什麼是得到的第一個項目檢查?

回答

1
$checked_list=$_POST['check_list']; 

if(empty($checked_list){ 

    echo "Please select field!"; 

}else{ 

    for($i=0;$i<count($checked_list);$i++){ 

     echo $checked_list[$i]."Checked"; 

    } 

} 

希望工程....

+0

感謝,它僅顯示其中有檢查,我需要知道什麼箱子已經得到了首先檢查的項目 – seven