The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/printthread.php(287) : eval()'d code 2 errorHandler->error
/printthread.php 287 eval
/printthread.php 117 printthread_multipage



UserSpice
Retrieving data from database - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: Retrieving data from database (/showthread.php?tid=1288)

Pages: 1 2 3 4 5 6 7


RE: Retrieving data from database - LBC - 01-10-2019

I guess if I dont want to offer dodgeball on a Sunday, I would not add that code to that day Smile
That is how I would do it anyway...but that's more because I have no idea what I'm doing.


RE: Retrieving data from database - mudmin - 01-10-2019

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.


RE: Retrieving data from database - mudmin - 01-10-2019

This is the whole thing with the functions. The only thing I changed was adding a times array to set the times and I had to reformat the table. The functions are the same

https://pastebin.com/UzSFN00N


RE: Retrieving data from database - LBC - 01-10-2019

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).


RE: Retrieving data from database - mudmin - 01-10-2019

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.


RE: Retrieving data from database - LBC - 01-10-2019

oww...ofcourse! Duh! Silly me. Sorry
Mudmin Sad


RE: Retrieving data from database - mudmin - 01-10-2019

It's not your fault. I wrote it Smile


RE: Retrieving data from database - LBC - 01-10-2019

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.


RE: Retrieving data from database - mudmin - 01-10-2019

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.


RE: Retrieving data from database - mudmin - 01-10-2019

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.