English 中文(简体)
Visibility schedule
原标题:

I want to have a simple database table to keep track of scheduled category visibility on a site index. Basically it will tell the index to display a Christmas category between Thanksgiving and Christmas day.

So far I m thinking of using a table like this,

schedule_id SMALLINT,

start_date TIMESTAMP,

end_date TIMESTAMP,

category_id SMALLINT,

annual BOOL

Simple enough, the database can select any rows where the time falls between start/end.

My issue comes in with my annual flag. Basically I m thinking that once a day the database can update the table, and add one year to any row where end_date < now and annual is true, otherwise delete the row if it s expired.

I m worried that leap years or something could offset the rescheduled date.

Am I on the right track here ?

Is there a better way to do this ?

最佳回答

If you add one year, rather than (say) 365 days you won t need to worry about the leap year issue.

 ADDDATE( date, INTERVAL 1 YEAR )

Adding 1 year to a leap day date gets you 28th February for the following year

2008-02-29 -> 2009-02-28

You might consider breaking your schedules out from your categories and having a join table linking categories to schedules. Then if you want to share a schedule betwen categories its a little easier. And potentially you can use the schedules elsewhere by adding other join tables.

Last suggestion, rather than having an annual field, have a nullable field to indicate a periodicity: weekly, monthly, etc., again gives you a more flexible schedule model.

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签