haha. That's exactly the answer I would have given. That's fine. I'm about to start doing a video series on building a userspice project from beginning to end. I'll show how to be more dynamic there. Gimme a sec.
That doesn't seem to work. It is saying that there are 6 spots available on each day (while that is not the case...looking at the old code on a different page).
Ahh. Because we're getting the days of the week differently.
Under global $db; add the line
$day = strtolower($day);
Since the array of days are capital and the database uses lowercase, it was throwing it off.
01-10-2019, 10:49 AM
(This post was last modified: 01-10-2019, 10:49 AM by LBC.)
So, if I wanted to have this function to also check the time in the database...that would be something like this? :
$count = $db->query("SELECT day FROM users WHERE day = ? AND time = ?",array($day).($time))->count();
That would make it more dynamic right? So I could have yoga at 10:00 and dodgeball at 15:00 on a Friday.
Not really because that would require too much in your users table to work. If I were trying to do it simply in one table, I would do a table called events with one line per event and the columns
id
event
monday_time
monday_spaces
tuesday_time
tuesday_spaces
etc
That's not the most dynamic way of doing it, but it's the simplest to comprehend.
Then when you add dodgeball, you add the event, and the time/spaces for each day.
Then signups would go in another table called signups
id
event_id
user_id
day
Then you cross reference the two tables.
That's where the user_id comes from. When a user signs up, their id gets inserted into the signups table, so if
yoga is event 1
dodgeball is event 2
my signup would look like
id = whatever(doesn't matter)
event_id=2(dodgeball)
user_id=17(my id in the users table)
day = wednesday
Basically that signup table ties the users table (user_id) together with the events table (event_id) and adds the day that I want to sign up for. All of a sudden we have these 3 tables that work together without caring how many rows the other has. You can have unlimited users, unlimited events and unlimited signups and because the ids "relate" the info from one table to another, it's infinately dynamic.
My adding to the users table you have to keep creating my more events and more times and more everything until it gets out of control.
There are ways to make it more dynamic (more than one yoga per day etc), but like I said, this is how that works at its core.
You'll notice we do the same thing in userspice.
The pages table is an id for each page.
The permissions table is an id for each permission level
page_permission_matches determines which permission level can visit which page.