Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: PHP Question

  1. #1
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default PHP Question

    Hi

    At the moment, I have a thing on an air cadet website, which says:
    The uniform for 12/10/09;
    • Working Blues
    Now, they're both stored in a MYSQL database, and it fetches it from there. However, I have to manually update the date, and this is a bit anoying.

    So is it possible to use PHP to automatically see what the date is for the next Monday or Friday, and produce it in a 6 digit date format?

    Thanks
    Luke

  2. #2
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:

    PHP Code:
    <?PHP
    $mysql_day 
    mysql_query("SELECT day FROM uniform");

    $spoons date('d-m-Y'strtotime('next $mysql_day'));
    echo 
    $spoons;
    ?>
    That code is totally horrible but I believe that is the kind of thing you would want, i.e.

    PHP Code:
    date('d-m-Y'strtotime('next monday')); 
    Would give the date of the next monday.

  3. #3
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Quote Originally Posted by Johno! View Post
    The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:

    PHP Code:
    <?PHP
    $mysql_day 
    mysql_query("SELECT day FROM uniform");

    $spoons date('d-m-Y'strtotime('next $mysql_day'));
    echo 
    $spoons;
    ?>
    That code is totally horrible but I believe that is the kind of thing you would want, i.e.

    PHP Code:
    date('d-m-Y'strtotime('next monday')); 
    Would give the date of the next monday.
    Hey, Im pretty noobish at php,a nd don't fully understand that code, could you explain further ;p

  4. #4
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Quote Originally Posted by Johno! View Post
    The only way I can see of doing it is something like having another row in the MySQL DB (day - either monday or friday) then having something like this:

    PHP Code:
    <?PHP
    $mysql_day 
    mysql_query("SELECT day FROM uniform");

    $spoons date('d-m-Y'strtotime('next $mysql_day'));
    echo 
    $spoons;
    ?>
    That code is totally horrible but I believe that is the kind of thing you would want, i.e.

    PHP Code:
    date('d-m-Y'strtotime('next monday')); 
    Would give the date of the next monday.
    yeh even though Johno made a few mistakes, strtotime is a good function. It converts a string time to a unix timestamp.

    strtotime('24th September 2008');

    Something like that or w/e

  5. #5
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Right, just had a look at php.net - confused even more haha ;p
    Soo, could someone help me, atm I have

    echo (' The next uniform is $uniform[date]; ...');
    etc

    So, what have i got to replace that with?


    Sorry for fuss
    Luke

  6. #6
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    Right okay, what I had here before didn't work haha. It should have given the date for monday. Im not the best at PHP haha. Im sure Protege will be able to give you a working method
    Last edited by Johno; 10-10-2009 at 06:57 PM.

  7. #7
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Right, done that, but its showing the date as Friday, not monday :S

  8. #8
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Update:
    Sorry for double post

    Swapped the thing around so it sayd if saturday||sunday etc
    and it worked;

    Many Thanks! and +rep if i can.
    Luke

  9. #9
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Instead of making another thread, decided just to post here again;

    Anyways, it worked, until it got to today, and now, its showing next Monday instead of next friday..

    Heres my code;

    PHP Code:
    <? 
    if (date("l") == "saturday"||"sunday") {
    $day "monday";
    } else {
    $day "friday";
    }
    $date date('d/m/Y'strtotime("next $day"));
    echo(
    " The uniform for $date<br /> • <i>$uniform[uniform[</i>");
    ?>
    took out some of the unneccesary code
    Last edited by Luke; 12-10-2009 at 03:18 PM.

  10. #10
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    PHP Code:
    <?php

    if( date'l' ) == 'saturday' || date'l' ) == 'sunday' )
    {
        
    $day 'monday';
    }
    else
    {
        
    $day 'friday';
    }

    $date date'd/m/Y'strtotime"next {$day}) );

    echo 
    'The uniform for ' $date '<br /> • <i>' $uniform'uniform' ] . '</i>';

    ?>
    Last edited by Protege; 12-10-2009 at 06:11 PM. Reason: Oopsy daisy
    Hi, names James. I am a web developer.

Page 1 of 2 12 LastLast

Posting Permissions

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