我在这里有这个查询:
function movement_performed_today($class_id, $client_id){
$class_id = (int)$class_id;
$client_id = (int)$client_id;
$query = mysql_query("SELECT COUNT(`movement`) FROM `completed_movements` WHERE `class_id` = '$class_id' AND `client_id` = '$client_id' AND `date` = CURDATE()");
$movement_performed = mysql_fetch_assoc($query);
print_r($movement_performed);
}
这将返回:
Array (
[COUNT(`movement`)] => 0
)
Array (
[COUNT(`movement`)] => 0
)
哪个是对的。现在我想做这样的事情:
function movement_performed_today($class_id, $client_id){
$class_id = (int)$class_id;
$client_id = (int)$client_id;
$query = mysql_query("SELECT COUNT(`movement`) FROM `completed_movements` WHERE `class_id` = '$class_id' AND `client_id` = '$client_id' AND `date` = CURDATE()");
$movement_performed = mysql_fetch_assoc($query);
return (mysql_result($movement_performed['count'], 0) == 1) ? true : false;
}
这样我就可以在 while 循环中调用这个函数,如果它返回 0/false,它会将表单数据发布到数据库。有人可以帮忙吗?这是我尝试执行此功能的 while 循环:
if (empty($_POST)=== false){
$i = 0;
while (isset($_POST["first_name"][$i])) {
$movement_data = array(
'user_id' => $session_user_id,
'class_id' => $class_id,
'class_name' => $class_name,
'client_id' => $_POST['client_id'][$i],
'first_name' => $_POST['first_name'][$i],
'last_name' => $_POST['last_name'][$i],
'nickname' => $_POST['nickname'][$i],
'order' => $_POST['order'][$i],
'movement' => $_POST['movement'][$i],
'rep_set_sec' => $_POST['rep_set_sec'][$i],
'rest' => $_POST['rest'][$i],
'date' => $today
);
$movement_performed = movement_performed_today($class_id, $_POST['client_id']);
foreach ($movement_performed as $performed){
if($performed == false){
completed_movement($movement_data);
} // if performed
} // foreach
$i++;
} // while
} // if empty