嘿家伙即时通讯具有带阵列的麻烦。我需要的是查询到基于记录ID更新表2列多个更新阵列查询出错:(
表有一个名为OffID列它会查找任何尚未被授权的记录,为了标记授权,用户将选择授权或拒绝的复选框,然后按下提交按钮,但目前我有9个记录,每个记录显示在表中有自己的唯一ID,但是当提交被选中时,它只会更新一个。任何帮助显示出错的地方将是感激和欢呼提前:)
好吧我编辑的代码,但它现在只设置冷杉t记录。因此,如果有8条记录,我选择接受的第一条记录,并拒绝对第二个记录同时接受和拒绝被设定为第一个记录在数据库中我的新代码如下
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/Apollo/dbc.php";
include_once($path);
$rs_results = mysql_query("SELECT * FROM off WHERE IsItAuthorised='0' and isitsick='0' ORDER BY DayOff");
?>
<html>
<head>
<title>Administration Main Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if (isset($_POST['submit'])) {
//Assign each array to a variable
$id = $_POST['id'];
$approve = $_POST['approve'];
$deny = $_POST['deny'];
$limit = count($rs_results);
$values = array(); // initialize an empty array to hold the values
for($k=0;$k<$limit;$k++){
$msg[] = "$limit New KPI's Added";
$query = "UPDATE off SET Authorised = '$approve[$k]', Deny = '$deny[$k]' WHERE OffID = '$id[$k]'";
}
$Event = "INSERT INTO events (UserName, Event) VALUES ('$_SESSION[user_name]', 'Entered New KPI')";
echo $query;
if (!mysql_query($query,$link)){
die('Error: ' . mysql_error());
} else {
mysql_query($Event);
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
}
?>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%" valign="top"><?php
?>
</td>
<td width="74%" valign="top" style="padding: 10px;">
<p><?php
if(!empty($msg)) {
echo $msg[0];
}
?></p>
<p>
<?php
$cond = '';
$sql = "select * from off ";
$rs_total = mysql_query($sql) or die(mysql_error());
$total = mysql_num_rows($rs_total);
?>
<p>
<form name "searchform" action="/Apollo/Admin/HolidayRequests.php" method="post">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr class="mytables">
<td width="4%"><font color="white"><strong>ID</font></strong></td>
<td width="4%"> <font color="white"><strong>Staff Member</font></strong></td>
<td width="10%"><font color="white"><strong>Day Off</font></strong></div></td>
<td width="10%"><font color="white"><strong>Is It Authorized</font></strong></div></td>
<td width="15%"> </td>
</tr>
<tr>
<td> </td>
<td width="10%"> </td>
<td width="17%"><div align="center"></div></td>
<td> </td>
</tr>
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td><input name="id[]" id="id[]" size="4" value="<?php echo $rrows['OffID'];?>" /></td>
<td><?php echo $rrows['StaffMember']; ?></td>
<td><?php echo date('d/m/Y', strtotime($rrows['DayOff']));?></div></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['IsItAuthorised']) { echo "Pending"; } else {echo "Authorized"; }?>
</span> </td>
<td>
<input type="checkbox" name="approve[]" id="approve[]" value="1"> Approve
<input type="checkbox" name="deny[]" id="deny[]" value="1"> Deny
</td>
</tr>
<?php } ?>
</table>
<input name="submit" type="submit" id="submit" value="Submit">
</form>
</p>
<?php
?>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td width="12%"> </td>
</tr>
</table>
</body>
</html>
请删除不必要的空格,而把代码,特别是行 - 空白.. :) – 2012-02-01 12:38:44
我个人会改变这个,所以它没有列出每一条记录,并在同一时间发布。我建议从审批过程中分离历史记录显示,并且只在编辑时更新单个记录。随着时间的推移,它的表现会变得非常糟糕,每年有100人参加2.8k。它可能会开始达到邮政大小限制,因为它会在每次修改时发送整个表格,并且更新速度很慢。我还会注意到,加强SQL注入是明智的做法,因为它可能会删除整个数据库。 – corrodedmonkee 2012-02-01 13:13:32
它只提取未经授权的记录,每天查看,通常只有大约5条记录。我只是需要它看看它目前在哪个ID和张贴到 – slowie 2012-02-01 13:26:12