I have a mysql table - request_events with three fields; request_eventsid,datetime,type.this table will track all the activities of my website day wise and also type wise.thus,type may be 1 or 2.I need to display an open-chart for understanding the progress.So I need to retrieve the ratio of type2/type1 as input day wise.How can I get all these input for last 30 days from this table.Please give me some idea....It already kill my week end.Please help me
You can get 30-day type-wise event counts with a query something like:
SELECT COUNT(type) FROM request_events
WHERE
datetime > DATE_SUB(CURDATE(),INTERVAL 30 DAY)
GROUP BY type;
You can use smart chart maker. it can help you generate any charts that is fed directly from your MySQL database, it does support a data filter option, from which you can specify the exact data you want to display in your chart, and finally it supports aggregation functions such as "count, sum, avg,..etc)
You can use smart chart maker for any types of charts. For more information please watch this video tutorial
Related
Please I need help, I would like to know if there is any way to create a calendar-like grid that will display the In and the Out time of several people. I have created a table that has the following fields:
code as integer
name as varchar
date as datetime
Therefore, a record on the table would look like this:
1234,Mark Claus,2015-09-01 07:49:00 for an IN hour
1234,Mark Claus,2015-09-01 18:03:00 for an OUT hour
Lets say I have 15 people, and 15 records for the month of september, here is the question:
Is there a way to display this in a grid using php to call the data in the table? Something like:
Name In/Out 1 2 3
Mark CLaus In 7:49 8:04 7:44
Out 6:03 5:04 5:44
Clara Vann In 7:49 8:04 7:44
Out 6:03 5:04 5:44
The table does not store weekends, but weekends should be displayed in the grid with something like 00:00 , so that it would look like a calendar. I have searched for something similar on the internet but I have not found anything yet.
I would like to avoid using Javascript, or Crystal Reports to do it, is it possible?.
Thanks for the assistance on this.
I'm working on a calendar application where you can set events which can last multiple days. On a given date there can be multiple events, already started or starting that day. The user will view everything as a calendar.
Now, my question is: which of the following is the right approach? Is there an even better approach?
1) use 2 tables, events and events_days and store the days of every event in the event_days table
2) use just one table with the events stored with a date_from field and a date_to field and generate every time with mysql and php a list of days for the desired range with the events
Obviously the first option will require much more db storage, while the second one will require a bigger work from the server to generate the list (every single time the user asks for it).
The db storage shouldn't be a problem for now, but i don't know if will be the same in the future. And i fear the second option will need too many resources.
I have used both approaches. Here is a list of pros and cons that I have noticed:
Two tables: events(id) and events_dates(eventid, date)
Pros:
Query to check if there are events on a given date or between given dates is trivial:
SELECT eventid FROM events_dates WHERE date BETWEEN '2015-01-01' AND '2015-01-10'
Query to select the list of dates for an event is trivial
SELECT date FROM events_dates WHERE eventid = 1
Cons:
While selecting the list of dates is trivial, inserting the list of dates for an event requires scripting (or a table-of-dates)
Additional measures required to make sure data remains consistent, for example, when inserting an event spanning three days you need four insert queries
This structure not suitable in situations where time is involved, for example, meetings schedule
One table: events(id, start, end)
Cons:
Query to check if there is are events on a given date or between given dates is tricky.
Query to select the list of dates for an event is tricky.
Pros:
Inserting an event is trivial
This structure suitable in situations where time is involved
In teaching myself php and mySQL a year or two ago, I created a movie database for the theater I work at, to help automate the more mundane web updates that need to be done weekly. So far this only pertains to film information (title, ratings, synopsis, start date) - but does not include showtimes, but lately I've thought it might be fun to see if it's possible to build on this aspect of the site.
My initial idea was to build a table that displayed showtimes via date groups (ie 5/15 - 5/20), but it was suggested that submitting times for individual days would probably be more useful from a user perspective (ie the showtimes for 5/15 are...), especially since there are occasionally changes and cancellations throughout the week due to special events.
Problem I'm having even starting this - is how to submit more than one date at once. Would it be possible, in the form, to have a 'start date' and 'end date' and have the single form submit all the times input on those two dates and all the dates inbetween?
From a back-end perspective submitting the same 4 or 5 showtimes every day, 7 days a week for 10 to 14 films a week is more work for US than just putting the times in manually in dreamweaver - so I'm just trying to figure out how to make the process easier for us behind the scenes. If we could batch insert a set of showtimes, then we could go back through and edit the individual days that have special/cancelled times (which would probably mean building in a 'draft, live, hidden' system - but I've got at least a basic knowledge of how to go about that.
I've got a very basic table set up for showtimes with (user end example of what I'm aiming for here):
MOVIE_ID (links with the movie info database to pull in film info - title, runtime, etc)
sched_date (uses datetime to set a specific showtime on a specific date)
I guess I might have to abandon using datetime if there's any way to do this?
Any help would be hot! Much thanks!
You can have 2 date fields with names from_date and end_date in your PHP form. In your PHP form submit code you then need to use the DateTime class and start from from_date and use the DateTime::add method to loop till end_date is reached. Please note you need to first convert the 2 dates i.e. from_date and end_date to datetime using either new DateTime('YYYY-MM-DD') or using DateTime::createFromFormat.
In the loop simply send insert commands to MySQL to insert the rows to your DB.
So what I'm doing is storing data from a website every 4hrs. I want to have a line graph of the last two days, the y-axis would be number of players and that value can be anywhere from 0-30,000, the value is dependent on the scrape of the website.
What is the best way to store the data in mysql and where is a easy to use graphing solution?
Has anyone used Raphaël?
Hey, Google Charts is exactly what you're looking for. It can create any type of chart from a data set, and is very customizable.
As for the actual data retrieving, the answers above will help you. :)
You could have a table structure like
Player_Stats
players int
hour int
Then each hour you could write something like:
insert into Player_stats (players, hour) values(NUMBEROFPLAYERS, HOUR#);
Where HOUR# is a value from 1 to X number of possible hours (if you want to only store things in a running log, otherwise, change hour to a timestamp)....the insert would be more like
insert into Player_Stats (players, timestamp) values(NUMBEROFPLAYERS, NOW());
Then you'd retreive your data with:
select players, hour from Player_Stats;
Or if you kept things in perpetuity and wanted to grab a range from now to 2 days ago:
select players, timestamp from Player_Stats where timestamp between now() and date_sub(timestamp, interval 2 day);
Then you could use a charting library like Google Visualizations...they have good documentation on formatting the data specifically for their different charts.
I've done something similar. I stored the number of players along with a time stamp in a table, then used jquery and jqplot to display the data.
I would set up a cron to run a SELECT TO OUTFILE myFile statement regularly. Note that myFile cannot be an existing file for security purposes (docs), so you'd have to have the cron also delete the file after the plot is created.
I have found ploticus to be very easy to work with, and can make some very complex plots without too much difficulty.
I am developing a website which will have 200.000 pages. There is also a browse section, which shows most popular, highest rated etc. documents. However this section will become almost static couple of weeks later, after launch. So I also would like to implement a filtering system which will show today's, this week's, this month's most popular items, just like youtube.
Just like this:
http://www.youtube.com/videos?c=2
How should I implement this function? Do I need another table, which will have a new entry for every document each day?
docid, date, view_count, rating
So I will get today's row for filtering by using a day, or calculate a week (7 rows) for filtering by using week? It seems not efficient. Do you have any suggestions?
I am using LAMP stack by the way.
Thanks,
Assuming you timestamp the records in your table, you should be able to put a where clause that limits the timestamp to whatever timeframe you want.
You can cache the result, especially the longer ones, for long enough to make the request inconsequential.
EDIT
But perhaps you mean most popular today, not most popular that was added today?
In which case, I don't have an answer.
The most direct approach is to save the timestamp and the resource id each time the resource is shown in recent_views(what, when). Daily/weekly/monthly charts can be created with appropriate WHERE clauses like WHERE when > $beginOfPeriod AND when < $endOfPeriod.
For performance reasons you can aggregate the values each night, save the sums in separate tables like daily_views(what, sum) and truncate the source table.
I guess I would calculate the date's in code and then pass them as arguments, to the SQL you are using.
I would do it using a compiler. Youtube probably does that too, considering the amount of traffic and the response times.
The principle is easy to understand. You log every every view or rating in a page_view table. You define periods at which the compilation occurs (hourly, daily, weekly, monthly). Every time you hit the good time (e.g.: end of the day), you execute the compiler, which essentially execute a query à-la...
SELECT * FROM page_view WHERE date > $from_date AND date < $to_date
... and store the result. This probably works better in a cron job.
The next time you need to display the information, you can just fetch the stored result and display it without re-computation. There are a variety of storage methods you can use: a MySQL table (e.g.: page_view_compiled), memcached, etc.