我有一个脚本,允许用户对图像进行评分,然后将另一个表单动态添加到页面以对下一个表单进行评分。当输入图像等级时,它会被输入数据库并显示在新创建的表单上方的页面上,并以 ID 的列表形式显示responds
。
所有这些都很好用,但我还可以在页面顶部显示已审核的图像数量,DIV
其中 ID 为results
。
这JQuery
$("#FormSubmit").click(function (e) {
e.preventDefault();
if($("#grade").val()!='1')
{
if($("#positioning_reason").val() == '' &&
$("#exposure_reason").val() == '' &&
$("#equipment_reason").val() == '' &&
$("#patient_reason").val() == '')
{
alert("Please select why the image was not perfect");
return false;
}
}
jQuery.ajax({
type: "POST",
url: "response.php",
dataType:"text",
data: $('#test_form').serialize(),
success:function(response){
$("#responds").append(response);
$('#test_form')[0].reset();
$("#test_form").get(0).scrollIntoView();
$("#results").display $numRows in this div
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
响应.php
//include db configuration file
include 'includes/db_connect.php';
if(isset($_POST['grade']))
{
$grade = $_POST['grade'];
$positioning = $_POST['positioning_reason'];
$exposure = $_POST['exposure_reason'];
$patient = $_POST['patient_reason'];
$equipment = $_POST['equipment_reason'];
$user_id = $_POST['user_id'];
$audit_id = $_POST['audit_id'];
$sql= "INSERT INTO image(auditID, imageGrade,positioning_reasonID,exposure_reasonID,patient_reasonID,equipment_reasonID,auditDate,userID) VALUES('$audit_id', $grade,'$positioning','$exposure','$patient','$equipment',NOW(),$user_id)";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
if($result)
{
$sql = "SELECT * FROM image WHERE auditID = '$audit_id'";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
$numRows = mysqli_num_rows($result);
$my_id = mysqli_insert_id($mysqli);
$output_array = array(
'my_id' => $my_id,
'grade' => $grade,
'numRows' => $numRows
);
}else{
header('HTTP/1.1 500 Looks like mysql error, could not insert record!');
exit();
}
}
elseif(isset($_POST["recordToDelete"]) && strlen($_POST["recordToDelete"])>0 && is_numeric($_POST["recordToDelete"]))
{
$idToDelete = $_POST["recordToDelete"];
$sql = "DELETE FROM image WHERE imageID = $idToDelete";
$result = $result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
if(!$result)
{
header('HTTP/1.1 500 Could not delete record!');
exit();
}
}
else
{
header('HTTP/1.1 500 Error occurred, Could not process request!');
exit();
}
echo json_encode($output_array);
我想在一个名为“结果”的 div 中显示值 $numRows(目前它与所有其他结果一起显示以用于测试目的)。我尝试使用页面下方的单独页面加载功能从不同的 php 页面获取 $numRow 值,但速度非常慢,并且由于时间问题,结果并不总是正确