Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Don't show results until certain time of the day

    Alright, so I have a table on my website that will have a list of jobs on it. Every day, that table or list of jobs will refresh to show the current jobs for that day.

    What's the best way to go about doing it?

    I would like to be able to add the jobs at anytime and make them only show on the day that the jobs are supposed to be completed.

    THE CATCH: I need this list only to display the jobs for that day AFTER a certain time of the day.

    So lets say today we had a list of jobs, they were completed.. The list would not show tomorrow's jobs until 8am the next morning. Once it's 8am, you can refresh the page and the list will be updated.

    I'm not sure how to do that..

    I hope I've explained myself so far. If you need any more information, please feel free to ask! Thanks for the help.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    Make a form to enter the jobs. They are stored in DB with a start date for each job. Set up a cron job to query the DB for jobs that have a start date of today and then refresh the list.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New Coder
    Join Date
    Aug 2014
    Posts
    97
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Yes a mysql database is the way to go on this idea. It can store all the data for the job and the start date / display date. You can query only the jobs needed by the current date or whatever timeframe you desire now or in the future. I don't think that a cron job is needed for this at all since you would just query the db on pageload and only display the results of that query.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    @ fastsol
    Hitting a DB every time someone comes to the page is a lot of server time. Especially when it is not necessary, a cron would do it only once a day.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    New Coder
    Join Date
    Aug 2014
    Posts
    97
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by sunfighter View Post
    Hitting a DB every time someone comes to the page is a lot of server time. Especially when it is not necessary, a cron would do it only once a day.
    I am new to this forum so I am certainly not trying to argue with a veteran here, but unless he's updating a static page or a static array of items on the php page, a call to the db is necessary anyway to get the info when the page loads. So why run a cron for something that is done every time the page loads anyway. We both know that the job info should be stored in a db anyway and that querying to the db multiple times on a page load for any normal site is extremely normal and if done properly doesn't slow the page load enough to out weigh the extra work involved in doing the cron.

    I am interested in knowing how and why you think a cron is a good way to go in this instance when the info still needs to be gathered from the db on page load. But if we are getting too off topic we can stop now.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    I disagree with Sunfighter. A dirt simple query, such as SELECT * FROM jobs WHERE jobdate == CURDATE() will execute nearly instantly, assuming you have created an index on the jobdate field.

    I do not understand the advantage of a CRON job. What would you have it do? Just copy all jobs for the current date from the jobs table to a jobs_today table? And then have the PHP code do SELECT * FROM jobs_today? That would have virtually no performance advantage over my example where jobdate is indexed.

    On top of that, since this is almost surely for an inTRAnet solution, where only employees of a given company are going to login and see the scheduled jobs, unless the company is Amazon or Microsoft, the number of logins is surely going to be no more than a thousand or two (and more likely under 100, else somebody who knew more about PHP would be creating this page). And 1000 or so "hits" on the server to get the jobs schedule MIGHT eat up 10 or 20 seconds of time, *TOTAL*, over the course of a day.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    As to the original question: How to get the list of jobs for today only after 8AM?

    Dirt simple, and can be done all in the SQL query:
    Code:
    SELECT * FROM jobs 
    WHERE jobdate = ( CASE WHEN HOUR( CURTIME() ) >= 8 
                           THEN CURDATE() 
                           ELSE DATE_SUB(CURDATE(), INTERVAL 1 DAY) 
                      END )
    That will show yesterday's jobs from 00:00:00 until 07:59:59 at which point it switches to showing today's jobs.

    It's worth investigating that code until you understand it. It's not complex.
    Last edited by Old Pedant; 08-16-2014 at 08:38 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    Quote Originally Posted by fastsol View Post
    I am new to this forum so I am certainly not trying to argue with a veteran here, but unless he's updating a static page or a static array of items on the php page, a call to the db is necessary anyway to get the info when the page loads. So why run a cron for something that is done every time the page loads anyway. We both know that the job info should be stored in a db anyway and that querying to the db multiple times on a page load for any normal site is extremely normal and if done properly doesn't slow the page load enough to out weigh the extra work involved in doing the cron.

    I am interested in knowing how and why you think a cron is a good way to go in this instance when the info still needs to be gathered from the db on page load. But if we are getting too off topic we can stop now.
    The OP hasn't been back for 4 days, so I'll assume he/she won't be and hijack the tread. Your wrong with this statement:
    ....when the info still needs to be gathered from the db on page load.
    Part of that cron job is to write the code for the job-table and save it. The main page uses an include or require statement to add it to the page. We access the DB once. It's the same as writing a page like this:
    PHP Code:
    <!DOCTYPE html>
    <html>
    <body>
    <div><?php include 'header.php';?></div>
    <div><?php include 'nav.php';?></div>
    <div>
        <p>Some text.</p>
        <p>Some more text.</p>
    </div>
    <div><?php include 'table.php';?></div>
    <?php include 'footer.php';?>
    </body>
    </html>
    As to why not just access the DB each time someone uses the site; It's like saying to your mother that your room is nearly clean. She wont buy it.
    hitting a DB 3,000 times a day is not efficient when you could have done it once.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    You are making the assumption (which might be valid...I certainly admit we can't possibly know from the limited info we were given) that the display based on the (assumed) query will be 100% identical (a) for all users and (b) throughout the day.

    My assumption was that, at the least, the list of jobs (especially, say, the percentage completed or which group is currently assigned the job) will change throughout the day. In my experience, in a typical company that is a pretty reasonable assumption. I just can't imagine a list of jobs that is static for an entire work day.

    Another thing that is likely to make a difference might be WHO is inspecting the list. I can well imagine (and my experience says this is likely) that supervisors will see more information in the list than will the peons actually doing the work. And even here there would likely be levels of supervisors with different info at each level.

    So... different assumptions, different answers. I should have stated my assumptions. Mea maxima culpa.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •