Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

SQL/PhP news page.

Hello,

I am in progress of making news page. My database table has the following rows: id, title , article, expiration_date, date_uploaded, state.

state is a boolean: 0-expired 1-active ; Now i want to check if expiration_date is passed if so i want to change the state to 0;

My questions are:

  1. Is this a good way to solve this problem.
  2. If it is then is there way to do this check with SQL or i have to use php and update state with query.

2 Answers

You could take some pointers from a content management systems like Joomla, you could have the state field to turn it on or off but also have a publish start and end date. So you could then just display active articles that have a publish date between the start/end timeframe. Some simple php to build the query and then query your database should work great for this.

Robert Walker
Robert Walker
17,146 Points

I would use a script to check it daily, so once a day the script would do something like this:

$date = "" \\ what ever format your expiration_date is.

UPDATE table_name (state) WHERE expiration < $date VALUES (0);

\\ this is not a valid MySQL statement just a suggestion to what you might want to try