I've been staring at the mediawiki database for my site. I want to create a linear list of pages ordered by the original creation date of the page.
I can't find a timestamp anywhere that indicates the first creation date of the page.
I can find revision timestamps with no problem, in the revision table...but no original creation timestamp. Furthermore, "page_touched" won't work since all these pages were xml imported recently, so they were all touched.
Any ideas?
Based on the layout of the revision table. I did not test it, nor have seriously considered possible corner cases.
SELECT rev_page, rev_timestamp
FROM revision
WHERE rev_parent_id = 0
ORDER BY rev_timestamp
The first revision of a page has rev_parent_id = 0, so we take its timestamp as the creation timestamp.
Related
I have a MySQL Table, let's say for blog posts. They have a column status which cam be active or inactive and two columns which are optional: publish date and expire date for scheduling posts.
Which solution do you recommend for changing the status depending on the publish date and expire date? Can I do this with a PHP script or cronjob ?
EDIT 30.11.16 / 16:50
Perhaps I have to be more precise about my specific problem: I have a magento store and I would like to add the possibility to schedule teasers. I want to change the existing code as little as possible.
I would say, it depends, but as #ADyson sad you should't only work with a cronjob, because it show some posts that should have been expired.
But you think about to write a single class/function that handle the status and expiration / publish date logic. It will be a mess later, if you have the code copy in the cronjob and on different output pages.
I also would think about the status field, maybe it is not necessary, if you make some MySQL Selects like
...
WHERE publish_date>now() AND expire_date<now()
I think title is clear what is my problem. I am working with MySql I just wanted to know what was the first registration on my website and when I sorted the table according to timestamp, the id of people who registered on the website were not true. The Image bellow will show what do I mean:
and this is the code what phpMyAdmin created:
SELECT *
FROM `table`
ORDER BY `table`.`timestamp` ASC
LIMIT 0 , 30
whats wrong with my table time? and why id is not ordered same as timestamps
If we assume that id is an auto-increment field, then this is almost certainly due to the fact that timestamp column is not assigned at the same physical time the id column is assigned. For example, if you have a multi-page registration from a website application, the initial object may be inserted into the database to contain the initial data fields gathered on the first page. But perhaps the timestamp is only set after the final page of registration is complete. So depending on the time the user takes to complete registration, the timestamp can be out-of-sync with the id order.
There are multiple ways to work around this. One way is to assign timestamp when the record is first inserted into the database, or you could use a DB insert trigger to populate the timestamp field instead.
There is also the possibility that timestamp represents the date and time the user last modified their profile (or otherwise caused modification of the database record). In this case, the timestamp could be changing to a "future" value while the id stays constant.
I'm working on building a webapp and received a partial database schema. Some of the tables have datestamp columns to keep track of when the record was last updated.
My question is twofold: what is/are the purpose(s) or benefit(s) of tracking when a record was updated, and when should it be done?
Thanks
You would want an "updated_at" column if a user wants to sort or filter by when a row was last updated.
Look at Google Drive's main listing window. There is a column "Last Modified" that you can sort on, to look at documents that you most recently modified. You would need a database column with the last modified date to be able to sort by that value.
Another example is an API where API users only want to download new information, so they could filter (using a WHERE clause) for records that had changed only since their last download.
I apologize in advance that I don't know the terminology of the tools I'm trying to use.
I have a table of events with a startdate field (among others) and a related repeats table with a reference to the event id. The repeats table stores the days of the week on which the event repeats and whether it's monthly, weekly, etc. What I'm hoping to do is duplicate the repeating events within the SQL query so my final result will have the the same event in different places when ordered on start date, so I can limit the results for proper pagination.
I'm looking at creating virtual tables and cloning tables documentation, but I'm having trouble applying the examples to my situation.
Update:
Hopefully I can elaborate on this.
The basics of what I have now is SELECT * FROM 'events' WHERE 'start_date' >= TODAY() ORDER BY 'start_date LIMIT 20 which gets me every event from today on, but I'm paginating the results so only 20 are displayed at a time.
What I would like to do is create a temporary 'virtual' table with the events which have an associated repeat entry, on which I will change the start_date based on the repeat information. So if it's a weekly repeat, this second table would be filled with identical events except that each start_date would be 7 days from the last. Then I could do a join on these two tables, limit those results to the 20 pagination limit I want, and have a query result with the events in the correct place and easy to perform pagination on.
I understand that creating a function in mySQL might be on the right track as I imagine I would have to loop through some information for adding to dates. I only know the level of SQL one picks up by writing in PHP, so functions are a bit out of my scope, though it doesn't seem that it'll be too hard to pick up with a little reading. I'm more confused about how I would create a fake table, add entries to it in a loop and then use a join on it to merge it with the first query.
I'm also beginning to wonder about the overhead for doing this in mySQL and, should I be successful in getting this to work, how I might cache these results, though it's only an afterthought right now.
Thanks to those who are trying to help me, I'm having trouble getting this question into words for some reason.
Just a quick architecture question really on storing calendar data.
Basically, I have a database of services for rental. On the front end, there is a calendar to show either "Available" or "Unavailable" for every future date. In the back-end the user can set any date/date range to available or unavailable (1 or 0) on a jQuery calendar.
The question I have is how would you go about storing this data in mysql and retrieving it on the front end?
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
Cheers,
RJ
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
Yes, I'd go with that, except I would not remove the record when renting expires - you'll easily know a renting expired because it's in the past, so you automatically keep the history of renting as well.
After all, there is infinite number of available dates1, so you'd have to artificially limit the supported range of dates if you went the other way around (and stored free dates).
1 In the future. And, in some sense, in the past as well.
Also, I'm guessing you want some additional information in case a service is rented (e.g. name of the renter) and there would be nowhere to store that if renting were represented by a non-existent row!
Since the granularity of renting is a whole day, I think you are looking at a database structure similar to this:
Note how RENTING_DAY PK naturally prevents overlaps.
Alternatively, you might ditch the RENTING_DAY and have START_DATE and END_DATE directly in RENTING, but this would require explicit range overlap checks, which may not scale ideally.
Decide whether the default is Available or Unavailable.
Possible have all dates available and store the unavailable dates?
So default is Available?
Then you can put unavailable_start and unavailable_end - store it as a date field. For single days, unavailable_start = _end. Then it's easy to query for a month or any date range and return the unavailability periods in that range. Then have jQuery parse it to display the calendar details for those dates.