The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (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.2.25 (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


Retrieving data from database - LBC - 01-04-2019

Hello Smile

I am (still) not very well versed in php at all, but I fiddle with it anyway. I'll try to explain what I want to do.

I added a column to the users table named day. Every user has a day of the week in their profiles which is stored in that column.

Now I would like to show on a public page (in a sort of calendar) the number of people who have Monday or Tuesday, etc.
So if there are 5 users with Monday in their profile, I would like to show the number 5 on that calendar page (preferably on Monday).
If there are 2 people who have Wednesday in their profile, it shows 2 on the calendar page.

I'm sure something like that should be possible, but I cannot seem to get it right in UserSpice.

I think it probably should look like this more or less: $query = $db->query("SELECT * FROM users WHERE day = monday",array($day));
But then I don't know how to show/echo the results Sad

Can anyone please give me a hand with this?


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

Will all 7 days be on at once? Or are you just trying to show the current day? do you have a little bit of HTML that shows the type of calendar you want to do? Having that would help me give you both an answer and showhow I did it


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

Hello mudmin, thank you for your quick reply.

I was hoping to use the event calendar from Jamezs ( https://userspice.com/forums/showthread.php?tid=918&highlight=event+calendar ) as that is the only UserSpice event calendar that I could find really. But it doesn't seem like he ever continued that project unfortunately.

A real calendar would of course be preferable (as it just looks better) but It does not have to be a real calendar per se.
It could also just be a page where all the days are listed.
Something like this:

Monday: 5
Tuesday: 1
Wednesday: 2
Thursday: 0
Friday: 6
Saturday: 0
Sunday: 6

Even better would be to show the reverse of that.
There are 6 spots available on any given day, so if it could show the number of spots left that would be cool.

So Monday: 1 (as there are 5 users with Monday in their profile), Tuesday: 5, etc.


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

Ok. Give me a second. Are users "signing up" for a day? Like would you want a user to be able to change their day from this page?


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

Signing up (or off) for a day would be something that i would love to have yes.

But for now I was just thinking I would add all that manually (as the admin) to their profiles and have the results show on some public page so people could see how many spots were left (even if they are not a user or are not logged in)


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

Ok. And you have the days stored in a column called day and the day is in lowercase letters like monday not Monday right?


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

ehm...yes. I suppose I could just always enter it in small letters Smile


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

(01-04-2019, 09:39 AM)LBC Wrote: ehm...yes. I suppose I could just always enter it in snall letters Smile

Nope that's fine.


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

Ok. You should be able to paste the code from this in the middle of any userspice page and it should work.

https://pastebin.com/SaaHFVY7


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

Ooh! That is amazing! Thank you so much mudmin.
This really gives me something to work with now.

How would I go about it to get it like this:

Monday: 4
Tuesday: 6
Wednesday: ..
Thursday: ..
Friday: ..
Saturday: ..
Sunday: ..

Is there a line of code that i can just paste anywhere?