I've got a query which selects a list of the un-returned loans from my loan table, and so I'm trying to make a checkbox for each row of which when selected the value for the "returned" field is set to " 1”(真),单击提交按钮后,所选行应更新为“1”......由于某种原因,我的查询似乎没有显示所有未归还的书籍,尽管当我回显计数时,正确显示数字:S 这是我到目前为止的代码(提前感谢您的帮助!)
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Loan ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Username</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Book ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Return Date</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['loan_id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['loan_id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['username']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['book_id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['return_date']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="update" type="submit" id="update" value="UPDATE LOANS"></td>
</tr>
<?php
// Check if delete button active, start this
if($update){
for($i=0;$i<$count;$i++){
$update_id = $checkbox[$i];
$sql = "UPDATE $tbl_name SET returned = "1" WHERE loan_id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=test_checkbox.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>