I've had many issues trying to find the problem to no hope.
I have a user stats page where it shows their all-time stats but would like to add a weekly and monthly stat page. Using SQL or PHP is there a way to get the total number from Monday to Friday. It needs to be from Monday to Sunday then resets the count back to 0 on Sunday. Selecting from one date range to another won't work because it'll have to change dynamically or is that not possible?
I want the results to be like this:
Table structure as shown:
http://imgur.com/a/YZOuy
if you could help it would be much appreciated. thanks!
Related
I'm trying to set up a way to be able to step backward and forward through sets of time ranges.
I'm creating a simple display for my work's production floor. Every time a user scans a barcode a serial number is generated in our ERP system. In order to track progress throughout the day they want a display that will show how many serials (and because of that, how many widgets) were processed that day. The display would also show the previous shift's widgets. So at any given time you look at the display you'll see the current shift's progress, and then the previous shift's totals.
We run 3 normal shifts throughout the week. 1st shift 6am to 2pm, 2nd shift 2pm to 10pm, 3rd shift 10pm to 6am. Then on both weekend days we have a weekend shift that runs 6am to 6pm.
I currently have a spaghetti noodle mess of if/else statements that make this actually work, but I really want to clean it up and make it easier to maintain long-term.
So let's say it's Monday 1st shift. I want to grab Monday 1st shift's totals, but I also want to step backwards by 1 shift to the weekend shift and grab those totals to display. The weekend shifts are really what threw this for a loop because now I have to be aware of the day of the week. 3rd shift is a little leery as well because it crosses over into multiple dates. Is there a clean way to set this up? A library out there that lets me define these things easily?
Hope this made sense. Happy to clarify anything I'm missing. Thanks in advance for any guidance!
Maybe a shifts resource would be usefull.
creating a shifts table with id, start_date, end_date, shift_type,...
when scanning for a barcode:
if the current shift was already created, assign a shift_id to the barcode row
if not, create the shift row, and assign a shift_id to the barcode row
Benefits:
Very easy and fast query to get the results that you need
If shifts changes (starting hour, ending hour,...) it would still work (the only change needed is on the method that creates the shift row)
Comparing shifts results would be very easy
Have you tried using CarbonPeriod? Note that Carbon is already included in Laravel so there's no need to go and add it with Composer.
I want to create a website with an scheduling calendar.
My first idea is to use some free calendar template or download some free scheduling calendar. Then in my scheduling form, when someone request for an schedule, I will get the date he/she input and save it into the database then show it to the scheduling calendar.
But someone told me that, in my database, I should create a calendar table.
Which is the best way around?
The first one with only one table for schedule on my database or the second one with two tables for schedule and calendar?
I hope you get my idea.
It could be first one. One of option is to keep data by day of year.
you can draw your own calendar by counting day of year
actual day of yaer - date('z') + 1; //+ 1 because it is an array it starts from 0
then you can get number of days in each month
cal_days_in_month
and loop it x 12 with
here will be day of month with css style so it looks like calendar field
your i++ will bee number of days in month of course.
Keep records in database by year and day of year. you can do so much things this way
Hi I have a MySQL table of Facebook pages (fbpagesfancount) that has the total fan count by day since 01 Jan 2016.
The structure is like this:-
Pageid, Pagename, Updated_Date, Fan_Count
There are a number of specific days that are missing and do not therefore have fancount values due to Facebook API issues.
The days that are missing are usually single days, for example, there is a value for the day before and the day after.
I'd like to create a new table that has a record for every day since 01/01/2016 for each page (750 pages) and then update the days that are missing by averaging the day before and the day after the missing date.
Is this possible using MySQL only or should I write a script in PHP that performs this task and if so, any suggestions on the logic would be helpful.
Any other suggestions on how to tackle this issue would be welcome.
Thanks
Jonathan
Yes, it is possible in SQL only.
No, you should not attempt it as it is more complicated and for a single shot there's no need.
Yes, write a script in any language you know, for instance PHP.
I'm not sure why you even want to create a new table? You could add a flag to your current table saying its an origional count vs an average, and just find the missing numbers and add them in a script.
I'm new to MySQL and PHP but was wondering if someone could help me with a little project I'm doing for my boss.
I have a SQL database (MyDB) and a table in there (mytable) with two columns - the first column (index) is an auto-incrementing integer from 1-10, the second column (date) has different dates and timestamps in the format of Year-month-day time 2013-04-12 1326
I'm trying to create a simple PHP page that first gets the current date (easy enough) then looks at the table and shows the number of rows that fall within yesterday's date. For example, if I have 3 rows with 2013-04-11 XXXX and 2 rows with 2013-04-12 XXXX (and today is the 12th April 2013) the page will display 3. (The time is not important but we can't remove it from the table as it's auto created by one of the other staff's programs and he refuses to change it).
So far I've got my php page, done a connection to the DB and defined two variables:
$startdate = date('Y'."-".'n'."-".'d'." "."0000");
$enddate = date('Y'."-".'n'."-".'d'." "."2359");
As the timestamp doesn't matter I've gone for the min/max possible on the variables. I realise this will only give the current date, trying to work out how to get it to display the previous day as the date in the variable.
Now I'm trying to create a sql query that will count the number of rows where the date field falls within the startdate and enddate variables (-1 day) but not too sure where to start or how this would look. I then need to output this as a variable in PHP so I can echo it later in the page.
Anyone able to point me in the right direction? Hope any of this makes sense.
You could write a query with no params to do this (if its always just yesterday).
SELECT * FROM <table>
WHERE DATE_FORMAT(<date column>,'%j-%Y') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY), '%j-%Y');
Date functions in the where clause might not be super awesome performance wise
I hope somebody can help work out to do this. Basically, I have a php script which displays youtube videos and statistics from the youtube data json api. The thing is, I need to be able to show the total view count for the previous month as well as the current month. I can get the total view count for a video and if you look on youtube there is a graph underneath the video which shows the views for a few months. Is this possible?? If not, can is there any other way I could go about storing the previous months view count?
Thanks in advance.
Run a cron job that updates a monthly tick...
All you would need to do is store the value of views at the beginning of each month and when the next month arrives you calculate the difference.
Running the cron job would ensure that 30 days are up and that the values should be updated.
Ex.
$lastmonth = 2238923; // 2,238,923views at the start of this month
$currentview = youtubeview(); // However you get the current view
$thismonth = $lastmonth - $currentview; // Difference and when the month is over $thismonth becomes $lastmonth :)