2011-11-08 64 views
0

我用PHP编写了这样的代码,我需要从数据库中删除删除列中“删除复选框”的行。我想发送“验证”值(1或0)到数据库。但我不知道SQL命令来删除检查行,我不知道怎么去“验证”栏的值(因为它是不可能得到使用$_POST[$id])值。如何删除选中的列并发送单选按钮的值?

<?php 
    echo "<form action=\"index.php?go=save\" method=\"POST\"> 
     <table width=\"335\" border=\"1\"> 
     <tr> 
     <th width=\"19\" scope=\"col\">ID</th> 
     <th width=\"31\" scope=\"col\">Title</th> 
     <th width=\"33\" scope=\"col\">URL</th> 
     <th width=\"52\" scope=\"col\">Visitors</th> 
     <th width=\"28\" scope=\"col\">Hits</th> 
     <th width=\"52\" scope=\"col\">Verify</th> 
     <th width=\"27\" scope=\"col\">Edit</th> 
     <th width=\"41\" scope=\"col\">Delete</th> 
     </tr>"; 
    $query = mysql_query("SELECT * FROM posts ORDER BY visitors DESC"); 
    while($write = mysql_fetch_array($query)) { 
     $id  = $write['id']; 
     $title  = $write['title']; 
     $url  = $write['url']; 
     $visitors = $write['visitors']; 
     $hits  = $write['hits']; 
    echo" 
     <tr> 
     <td>$id</td> 
     <td>$title</td> 
     <td>$url</td> 
     <td>$visitors</td> 
     <td>$hits</td> 
     <td> 
     <input type=\"radio\" name=\"$id\" value=\"1\" />Yes 
     <input type=\"radio\" name=\"$id\" value=\"0\" />No 
     </td> 
     <td><a href=\"index.php?go=edit\">Edit</a></td> 
     <td> 
      <input type=\"checkbox\" name=\"$id\" /> 
     </td> 
     </tr>"; 
    } 
    echo "</table> 
     <input type=\"submit\" value=\"Save\" /> 
     </form> "; 
    ?> 

请, 。帮我解决这个问题,如果你知道的替代变量,请把它写

回答

0

删除列:

<input type=\"checkbox\" name=\"delete[]\" value=\"$id\" /> 

检查和删除:

foreach($_POST['delete'] as $id_to_delete) { 
    mysql_query("DELETE FROM posts WHERE ID=".$id_to_delete) 
} 
相关问题