我在while
中的echo
条件中有表单,因为在while条件下,某些值来自数据库,并且根据每一行,用户在表单中执行操作。
在表单中,复选框是复选框的onclick
,我希望PHP
代码在更新数据库的同一页面中执行。
echo "<tr><td>Assign employee ID</td><td>Task Assign</td><td>Date of Assigning Task</td>
<td>Given Task time</td><td>Time of given task</td><td colspan=3>Read message</td></tr></tr>";
$message=mysql_query("select * from message where receiver_id='$myid' and is_read != 1 ");
while($row=mysql_fetch_array($message))
{
$sender_id=$row["sender_id"];
$receiver_id=$row["receiver_id"];
$task_assign=$row["message"];
$date=$row["date"];
$time_of_given_task=$row["time"];
echo "<tr>
<td>".$sender_id."</td><td>".$receiver_id."</td><td>".$task_assign."</td>
<td>".$date."</td><td>".$time_of_given_task."</td><td>
<form action='message_to_read.php?date=$date&time=$time_of_given_task&receive=$receiver_id' method=post>
<input type=checkbox value=checked name=check onclick=foo();></td>
</form>
</td>
</tr>";
}
echo "</table>";
function foo()
{
$todaydate=$_REQUEST["date"];
echo $todaydate;
$time_of_given_task=$_REQUEST["time"];
echo $time_of_given_task;
$empid=$_REQUEST["receive"];
echo $empid;
$test2=mysql_query("update message set is_read='$update' where receiver_id='$empid' and date='$todaydate' and time='$time_of_given_task' ");
}
答案 0 :(得分:1)
对我来说看起来像AJAX问题。如果您使用的是JQuery,只需使用内置的AJAX功能。
$(document).on('change', '#YOUR_CHECKBOX', function() {
if ($(this).is(':checked')) {
//if checkbox is checked do ajax call
$.ajax({
type: 'post',
url: URL_TO_YOUR_PHP_SCRIPT,
data: { OPTIONAL : DATA },
success: function(result) { }
});
}
});
在这种情况下,更改事件会优于点击事件