Before I begin, THIS IS AN ASSIGNMENT. I am just after a helping hand an some guidance :)
I am developing a gym membership website which allows users to register, login, and book an activity.
I have everything working, besides the activity booking system, and that is what I need guidance with. I have a single txt file that contains an activity log of each activities name, time, how many can attend in total. I would like to add to the end of each activities line of who is attending exactly. Therefore, allowing users to book the activity, which adds their username to the activity.
This is exactly how I currently have my activity.txt file printing (besides the 'Book' buttons on the far right.
NumberOne 3 Wednesday 8am (BOOK)
NumberTwo 7 Thursday 10am (BOOK)
NumberThree 20 Monday 1pm (BOOK)
NumberFour 15 Tuesday 5pm (BOOK)
Basically, what I need guidance with is the 'Book' buttons. Once a 'Book' button is pressed, it will book the user in to the activity.
This is how my activity.txt file currently looks:
NumberOne,3,Wednesday 8am
NumberTwo,7,Thursday 10am
NumberThree,20,Monday 1pm
NumberFour,15,Tuesday 5pm
And this is the code I currently have that is printing the activities:
function bookActivity()
{
$fileContentsArray = file("activity.txt");
echo "<table>";
foreach($fileContentsArray as $one_persons_data)
{
echo '<tr>';
$splitted = preg_split('/,/', $one_persons_data);
foreach ($splitted as $one)
{
echo "<td>$one</td>";
}
echo '</tr>';
}
echo "</table>";
}
Below is my users.txt file if needed. All passwords are saved in MD5
jiten:3fc0a7acf087f549ac2b266baf94b8b1
jb:3fc0a7acf087f549ac2b266baf94b8b1
test:bed128365216c019988915ed3add75fb
joeBlogg:bed128365216c019988915ed3add75fb
userX:bed128365216c019988915ed3add75fb
userY:bed128365216c019988915ed3add75fb
All help is greatly appreciated. Very confused on how to do this.
Here's a rough guideline (I won't go in the specifics because it's homework after all) and I'll keep the assumption you're not allowed to use anything different than text file but can create/delete as many of them as you wish.
file(...)
with the proper flags setexplode()
here.when somebody press the "book activity" button, you'll have to do the following steps:
To show the list of the booked users, simply read the file contents from each activity file. You may find useful implode()
this time.
I hope this will help you finding the right track. A last note, text files aren't designed to do this: a small database is easier to use, more fun to learn and more useful for your future.
References:
file_put_contents(...)
file(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With