I have this query here:
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);
}
That returns this:
Array (
[COUNT(`movement`)] => 0
)
Array (
[COUNT(`movement`)] => 0
)
Which is correct. Now I want to do something like this:
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;
}
So that I can call this function inside of a while loop and if it returns 0/false it will then post the form data to the db. Can someone help? Here is the while loop where Im trying to perform this function:
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
movement_performed_todayin the loop before each insert no?mysql_queryin new applications. It's being phased out of PHP. You should be usingmysqlior PDO for all new code. Clever tricks like casting tointare no substitute for proper SQL escaping. If you develop bad habits like that, one day you will make a mistake, and those can cost you dearly.