lundi 28 mars 2016

How to create a series of checkboxes in HTML with PHP searching a MySQL database?

I want to create a series of checkboxes that the user can check off if they completed exercises that they have said that they have scheduled. So, for example, if a user of a website I am creating says that they will do a bench press and they schedule it, then it will appear in the schedule table in MySQL. But, after the date that they said they would complete the exercise passes, they will be alerted in PHP about the exercises to ask them if they really did complete it. If the user checks that they did complete the exercise, they check the box and the exercise will appear in their activity table in MySQL. If the user does not check the box, then the exercise will then go from being pending to being canceled.

My main problem is that I am just not sure how to create these series of checkboxes based on the exercises that the user has scheduled after the date has passed. I do not know how to create checkboxes without creating an arbitrary amount of them from the start.

Let's say the user said they would do a bench press on the date 01/01/2000 and the date has now passed. I have a date function in PHP that will only show the message if the date has passed. Here is the date function and what is followed is the if statement to check to see if the date is greater than or equal to the day variable from the table:

echo "Today is " . date("m/d/Y") . '<br>';
if(date("m/d/Y") <= 'day') {
echo "You have pending exercises: ";

and so on. But when I create checkboxes, I want them to only show up if the user has exercises, not just create a set number of them. So, if the user has 3 exercises that are pending, I want just 3 checkboxes for the user to click if they completed each exercise then click submit. If the user did not click any of them, they will appear in the schedule table as canceled via an SQL statement.

I have this just as a test statement, but it seems a bit convoluted at the moment:

if(empty($_POST['exercise1'])) {
    if(empty($_POST['exercise2'])) {
        if(empty($_POST['exercise3'])) {
            echo "Checkbox was left unchecked.";
        } else {
            echo "Checkbox was checked.";
        }
    }
}

Is there any way I can create a set number of checkboxes equal to the number of exercises that are in the schedule table and when the user clicks or does not click on them, they appear in the schedule table as either completed or canceled in PHP/SQL and HTML?

Sorry, I know this is a lot of information, but any tips would be appreciated. Thank you.




Aucun commentaire:

Enregistrer un commentaire