私はここにこのクエリがあります:
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が返された場合は、フォームデータをデータベースに送信します。誰かが助けることができますか?これが、Imがこの関数を実行しようとしている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