<div class="codetitle"> <span><a style="CURSOR: pointer" data="43027" class="copybut" id="copybut43027" onclick="doCopy('code43027')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code43027"> <br><?php <BR>@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器 <br>or die("数据库服务器连接失败"); <br>@mysql_select_db("test") //选择数据库mydb <br>or die("数据库不存在或不可用"); <br>$query = @mysql_query("select * from tablename1") //执行SQL语句 <br>or die("SQL语句执行失败"); <br>echo "<form method="post" name="form1" action="delete_do.php">"; <br>echo "<table border="1">"; <br>//通过循环的方式输出从第0行到最大的一行的所有记录 <br>for($i=0; $i<mysql_numrows>{ <br>$id = mysql_result($query, $i, 'id'); //输出第$i行的serial_no列 <br>$username = mysql_result($query, $i, 'username'); //输出第$i行的name列 <br>$password = mysql_result($query, $i, 'password'); //输出第$i行的salary列 <br>echo "<tr>"; <br>echo "<td><input type="checkbox" name="chk[]" value="$id"></td>"; <br>echo "<td>$id</td>"; <br>echo "<td>$username</td>"; <br>echo "<td>$password</td>"; <br>echo "</tr>"; <br>} <br>echo "<tr>"; <br>echo "<td colspan="4" nowrap> <input name="Submit" type="submit" value="提交">"; <br>echo "<input type="reset" name="Reset" value="重设"> </td>"; <br>echo "</tr></mysql_numrows> </table> </form>"; <br>?><br> </div> <br><br><div class="codetitle"> <span><a style="CURSOR: pointer" data="34741" class="copybut" id="copybut34741" onclick="doCopy('code34741')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code34741"> <br><?php <BR>@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器 <br>or die("数据库服务器连接失败"); <br>@mysql_select_db("test") //选择数据库mydb <br>or die("数据库不存在或不可用"); <br>foreach($_POST['chk'] AS $check) <br>{ <br>$query = mysql_query("delete from tablename1 where id = $check"); <br>if($query) <br>echo "删除成功"; <br>else <br>echo "删除失败"; <br>} <br>mysql_close(); <br>?> <br> </div>