Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

250

I have a Problem.
I am working on something like Message Forums.
Every Post Is Displayed only for 4 days Publically after Its Posted.
I store the date_entered values as time() in database (ie $now = time() and then store $now in date_entered field).

WHile Displaying the posts, I do Grouping
ie 1st Day, 2nd Day, 3rd Day and Final Day.
So those Posts which are Posted today come Under 1st Day Heading.

Problem is I dont have to count weekends(saturday/sundays) and some holidays that are defined by admin. So if I post on Monday and Monday is a holiday, Monday and Tuesday both will be the First Day.

If I post on Saturday, then sat/sun/mon will be First day (if monday is not a holiday). If monday is a holiday, then sat/sun/mon/tue all will be first day.

I hope I made myself clear.

How do I achieve this. I am all lost.
I have decided the best way to do is keep 4 fields in database (firstday, secondday, thirdday, fourthday) and while Inserting, do the calculations and insert proper values.  This way while displaying I can just select and Display, no hard calculations.

Any Code Samples for this?

0
desisant
Asked:
desisant
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
carchitectCommented:
Well....
my answer is little idiotic....


take two var...firstday and lastday....

make a table of dates which are not holidays....now fill both var...
by

firstday will be fielddate from table which is less than equal to today's date and fielddate is


like select max(date) from notholiday where date <=todays date

this way you will get first date which is not holiday....
then look to fill lastday....

select date from notholiday where date <=todaydate limit by 0,4

now just insert last row value in lastday


print all those records which comes between firstday and lastday

regards

0
 
VGRCommented:
not that bad carchitect :D

Other solution less consuming in tablespace :
-you are supposed to be able to find the holidays in a table somewhere. Let's say I can use IsNotHoliday($date) : Boolean;

-you can select easily "next Monday" using PHP (see Doc on date() or strtotime()  I guess)

-I suggest this algorithm :
+start from the now() date of input in the DB - BTW, you don't have to do $now=date() and "date_entered='$now'" in MySql query : just set "date_entered=now()" in MySql query ;-)
+if rank in week is >Friday (see doc about this format, sometimes 1 is Monday, sometimes it's - stupidly - Sunday), set it to next Monday
+check if IsNotHoliday(that Monday), if yes you're done
+if not, increment day of date until IsNotHoliday(date)
(this is supposed to happen in less than 3 queries)
0
 
desisantAuthor Commented:
VGR,

Could u help me with coding your algo.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
desisantAuthor Commented:
I have solved my Problem....Thanks Guys!
0
 
carchitectCommented:
hey could you pls post your solution
it will help us
0
 
VGRCommented:
ditto
0
 
techtonikCommented:
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now