我想出瞭如何使用複選框更新一個包含多個列的表格,除非選中了多個複選框時,更新將只發生在其中一列不同時。有人可以幫忙嗎?謝謝!我不能更新多列,只有一列會更新
下面是表的工作代碼:
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="frmactive" method="GET" action="assigncases1.php">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<select name="assigned_to">
<option value=""></option>
<option value="Kristin Dodd"> Kristin Dodd </option>
<option value="Matt Ursetto"> Matt Ursetto </option>
<option value="Derek Bird"> Derek Bird </option>
<option value="John Castle"> John Castle </option>
<option value="Martin Delgado"> Martin Delgado </option>
</select>
<br>
<input type='submit' value = 'Assign'>
</tr>
<tr>
<td> </td>
<td colspan="4" align="center"><strong>Update multiple rows in mysql with checkbox<br>
</strong></td>
</tr><tr>
<td align="center" bgcolor="#FFFFFF"></td>
<td align="left"><strong>Name</strong></td>
<td align="left"><strong>SSO</strong></td>
<td align="left"><strong>case_status</strong></td>
<td align="left"><strong>Assigned To:</strong></td>
</tr>
<?php
$result=mysql_query($sql);
$count=mysql_num_rows($result);
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox" type="checkbox" id="checkbox[]" value="<?
echo $rows['id']; ?>"></td>
<td><? echo $rows['full_name']; ?></td>
<td><? echo $rows['sso']; ?></td>
<td><? echo $rows['case_status']; ?></td>
<td><? echo $rows['assigned_to']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
這就是我對於採取信息PHP頁面。
// Retrieve data from database
$checkbox = $_GET['checkbox'];
$assigned_to = $_GET['assigned_to'];
// update data in mysql database
$sql="UPDATE rmstable2 SET assigned_to='$assigned_to' WHERE id='$checkbox'";
$result = mysql_query($sql);
$count = mysql_numrows($result);
{
mysql_query("UPDATE `rmstable2` SET `assigned_to` = '$assigned_to'
WHERE `id` = '$checkbox'")
or die(mysql_error());
}
//If they did not enter a search term we give them an error
if ($assigned_to == "")
{
echo "<h3>You forgot to enter a required field. Please try again.</h3><br>";
}
// if successfully updated.
else if($assigned_to !== "")
{
echo "<b>Update Successful</b><br>";
echo "<br>This case was assigned to:<b> $assigned_to</b><br>";
echo "<br>To see the change go back and click on <b>Refresh Page</b> if you assigned it
to someone other than you, the case will disappear and show up in their list of
assigned cases.";
}
else {
echo "ERROR";
}
?>
你應該真的使用CSS的顏色和佈局 – Don 2012-08-07 16:03:12
沒錯,這只是爲了表明我希望它看起來粗糙。我不知道怎麼說。 – Alexandra 2012-08-07 16:05:30