+ Post New Thread
Results 1 to 8 of 8
Web Development Thread, Theme Of the Week in Coding and Web Development; I'm currently trying to put the theme of the week on our new intranet - i'm slightly stuck with how ...
  1. #1

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351

    Theme Of the Week

    I'm currently trying to put the theme of the week on our new intranet - i'm slightly stuck with how best to do it.

    I have a spreadsheet which has all the themes but its week commencing so all is dated monday rather then change it all for each day of the week with the correct theme i was thinking of doing this


    PHP Code:
    $date =get date
    if ($date monday) {$theme =mysql query Selete from table where week=$date echo $theme} elseif ($date tuesday) { $theme =mysql query selete from table where week =$date -1day echo $theme} elseif etc for wed thurs and friday
    Enless anybody can think of a better way of doing it?

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    Just find the Monday date of the week that you're currently in, and then query on that.

    This function might help you. Give it today's date, and it will give you current/last Monday's date. All in yyyy-mm-dd format.

    PHP Code:
    function get_monday($date){
        
    // Find start of week of given date in format YYYY-MM-DD
        
    $dateparts explode('-'$date);
        
    $thedate mktime(000$dateparts[1], $dateparts[2], $dateparts[0]);
        if( 
    date("w"$thedate) == ){
            
    $monday date("Y-m-d"$thedate);
        } else {
            
    $monday date("Y-m-d"strtotime("last Monday"$thedate));
        }
        return 
    $monday;


  3. Thanks to webman from:

    glennda (23rd March 2011)

  4. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    I thought there might have been a better way to do it!

    Cheers

  5. #4

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    I've tried this

    PHP Code:
    function get_monday($date){ 
        
    // Find start of week of given date in format YYYY-MM-DD 
        
    $dateparts explode('-'$date); 
        
    $thedate mktime(000$dateparts[1], $dateparts[2], $dateparts[0]); 
        if( 
    date("w"$thedate) == ){ 
            
    $monday date("Y-m-d"$thedate); 
        } else { 
            
    $monday date("Y-m-d"strtotime("last Monday"$thedate)); 
        } 
        return 
    $monday
    }  
    $theme mysql_query("SELECT * FROM themes WHERE date = '$monday'");
    $themes mysql_fetch_array($theme);
                       echo 
    "<h2>" .$themes['theme']."</h2>" ?> 
    But I just get undefined variable monday?

    although it works with just the datestamp in the query
    Last edited by glennda; 23rd March 2011 at 05:04 PM. Reason: Correct my code!

  6. #5

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    You need to call the function get_monday() and give it a date (today's date). E.g.

    PHP Code:
    <?php

    // Define the function that gets the monday
    function get_monday($date){ 
        
    // Find start of week of given date in format YYYY-MM-DD 
        
    $dateparts explode('-'$date); 
        
    $thedate mktime(000$dateparts[1], $dateparts[2], $dateparts[0]); 
        if( 
    date("w"$thedate) == ){ 
            
    $monday date("Y-m-d"$thedate); 
        } else { 
            
    $monday date("Y-m-d"strtotime("last Monday"$thedate)); 
        } 
        return 
    $monday
    }

    // Call the function and assign return value to a variable
    $monday get_monday(date('Y-m-d'));

    // Run query
    $theme mysql_query("SELECT * FROM themes WHERE date = '$monday'");
    $themes mysql_fetch_array($theme);

    echo 
    "<h2>" .$themes['theme']."</h2>";
    ?>

  7. #6

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Ah right cheers will give it a go cheers

  8. #7

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Slightly off topic but i'm still trying to do the same thing!

    do you know a way that i can import the date from the excel spreadsheet (or csv) in yyyy-mm-dd format into a timestamp? as currently when i try and import it i just get 0000-00-00 00:00:00

    EDIT: i'm using phpmyadmin

  9. #8

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,821
    Thank Post
    272
    Thanked 1,140 Times in 1,036 Posts
    Rep Power
    351
    Not to worry i've sorted

    the reason it was strange before was the way the spreadsheet was holding the time data becuase the teacher had set the date in the yyyy-mm-dd format using excels format cell and it was displaying it as 4056 for example



SHARE:
+ Post New Thread

Similar Threads

  1. Front Page - Week 1 / Week 2 Display
    By mee in forum EduGeek Joomla 1.5 Package
    Replies: 0
    Last Post: 27th September 2010, 02:02 PM
  2. Old Theme
    By blumystique in forum EduGeek Joomla 1.5 Package
    Replies: 1
    Last Post: 11th March 2010, 03:43 PM
  3. [Ubuntu] Theme
    By neon in forum *nix
    Replies: 3
    Last Post: 4th November 2009, 11:25 AM
  4. new theme?
    By daboroe in forum EduGeek Joomla 1.5 Package
    Replies: 4
    Last Post: 26th July 2009, 08:07 PM
  5. Specify theme
    By Hightower in forum How do you do....it?
    Replies: 3
    Last Post: 24th July 2008, 02:54 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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