首页上一页 1 下一页尾页 1 条记录 1/1页
读《PHP数据库系统开发完全手册》第9章09-02补充
发表在PHP图书答疑
2008-03-25
是否精华
是
否
版块置顶:
是
否
<P>我读使用UPDATE语句实现批量更用户状态,174页倒数第二行中"PHP接收多个同名复选框信息,不像JSP那样可以自动转换成为数组,这给使用都带来了一定不便。"</P>
<P>我感觉这么说是不对的,PHP是可以接收同名复选框信息并转成数组的。只要把复选框名改成“id[]”,就可以接收数组变量值的。然后在用implode转是字符串形式。</P>
<P><?php <BR> include "conn/conn.php";<BR> $item = $_POST[items];<BR> $item =implode(",",$item); //字符串格式:1,2,3,4<BR> if( $item<>""){<BR> if ($_POST[Submit]=="激活"){<BR> $sql="update tb_member set Grade='激活' where M_ID in (".$item.")";<BR> $result=mysql_query($sql);<BR> }<BR> else{<BR> $sql="update tb_member set Grade='冻结' where M_ID in (".$item.")";<BR> $result=mysql_query($sql);<BR> }<BR> }<BR> else{<BR> echo "<div align='center' style='color:#FF0000; font-size:12px'>请选择一个用户</div>";<BR> }<BR>?></P>
<P><form name="form1" method="post" action="index.php" onSubmit="Checker()"> <BR> <table width="349" border="1" align="center" cellpadding="0" cellspacing="0" ><BR> <tr align="center" bgcolor="#efefef"><BR> <td height="36" colspan="3">用户列表<BR> </td><BR> </tr><BR> <?php<BR> $sql=mysql_query("select * from tb_member");<BR> $result=mysql_fetch_array($sql);<BR> do {<BR> ?><BR> <tr align="center"><BR> <td width="108"><input name="id[]" type="checkbox" id="id" value="<?php echo $result[M_ID]; ?>"></td><BR> <td width="131"><?php echo $result[M_Name]; ?></td><BR> <td width="88"><?php echo $result[Grade]; ?></td><BR> </tr><BR> <?php<BR> }while($result=mysql_fetch_array($sql));<BR>?><BR><tr align="center"><BR> <input type="hidden" name="items" value="<?php echo $item; ?>"> <BR><td colspan="3"><input type="submit" name="Submit" value="激活" > <BR> <input type="reset" name="Submit" value="重置"><BR> &nbsp;<BR> <input type="submit" name="Submit" value="冻结"><BR></tr><BR> </table><BR> <p>&nbsp;</p><BR></form></P>
<P>我感觉这么说是不对的,PHP是可以接收同名复选框信息并转成数组的。只要把复选框名改成“id[]”,就可以接收数组变量值的。然后在用implode转是字符串形式。</P>
<P><?php <BR> include "conn/conn.php";<BR> $item = $_POST[items];<BR> $item =implode(",",$item); //字符串格式:1,2,3,4<BR> if( $item<>""){<BR> if ($_POST[Submit]=="激活"){<BR> $sql="update tb_member set Grade='激活' where M_ID in (".$item.")";<BR> $result=mysql_query($sql);<BR> }<BR> else{<BR> $sql="update tb_member set Grade='冻结' where M_ID in (".$item.")";<BR> $result=mysql_query($sql);<BR> }<BR> }<BR> else{<BR> echo "<div align='center' style='color:#FF0000; font-size:12px'>请选择一个用户</div>";<BR> }<BR>?></P>
<P><form name="form1" method="post" action="index.php" onSubmit="Checker()"> <BR> <table width="349" border="1" align="center" cellpadding="0" cellspacing="0" ><BR> <tr align="center" bgcolor="#efefef"><BR> <td height="36" colspan="3">用户列表<BR> </td><BR> </tr><BR> <?php<BR> $sql=mysql_query("select * from tb_member");<BR> $result=mysql_fetch_array($sql);<BR> do {<BR> ?><BR> <tr align="center"><BR> <td width="108"><input name="id[]" type="checkbox" id="id" value="<?php echo $result[M_ID]; ?>"></td><BR> <td width="131"><?php echo $result[M_Name]; ?></td><BR> <td width="88"><?php echo $result[Grade]; ?></td><BR> </tr><BR> <?php<BR> }while($result=mysql_fetch_array($sql));<BR>?><BR><tr align="center"><BR> <input type="hidden" name="items" value="<?php echo $item; ?>"> <BR><td colspan="3"><input type="submit" name="Submit" value="激活" > <BR> <input type="reset" name="Submit" value="重置"><BR> &nbsp;<BR> <input type="submit" name="Submit" value="冻结"><BR></tr><BR> </table><BR> <p>&nbsp;</p><BR></form></P>