Results 1 to 9 of 9

Thread: Updating month <a name""> dynamically

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default Updating month <a name""> dynamically

    I have recently put events for my site into a database so it requires less work when updating. But I'm just trying to think of a way to code the following:

    Query database for the first event in a specific month, for example I have 3 events. Two at 03/01/09 (d/m/y), and another at 05/01/09. Since there can be two events on the same day, I want the one that comes first alphabetically to have the <a name="jan"> tag so it points to the beginning of that month. So it needs to loop through, check for the first occurrence of an event in a given month and then if there are duplicates, go to the first alphabetically. I feel this is a little bit tough of me, so any guidance would be greatly appreciated,

    Thanks,

    Jack.

    P.S - Just ask if you need anything explained in greater detail.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Bump, I know this thread hasn't been up that long but I really need a reply as soon as possible, can't put up the new version until I get this fixed,

    Thanks,

    Jack.

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Don't worry. I'm always trying. I am trying, but I also have a few other things.. if you want I can give you the current code:
    PHP Code:
    $months = array(
      
    => "Janurary",
      
    => "Feburary",
      
    => "March",
      
    => "April",
      
    => "May",
      
    => "June",
      
    => "July",
      
    => "Agust",
      
    => "September",
      
    10 => "October",
      
    11 => "November",
      
    12 => "December"
    );

    function 
    organizeMonths($date){ /*array*/
      
    global $months;
      for(
    $i 0$i count($date); ++$i){
        
    $date[$i] = explode("/"$date[$i]);
        foreach(
    $months as $key => $value){
          if(
    $date[$i][0] == $value){
            
    $date[$i] = $key.":".$value;
          }
        }
        return 
    sort($date);
      }
    }
    echo 
    organizeMonths(array("Janurary/03/2009")); 
    But it doesn't work yet. =/
    Jeremy | jfein.net

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok, well I just appreciate any effort I'll check tomorrow if you've done any more. Thanks for the code so far anyway

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, I found an easier way. You can mess around with it(it organizes by month - then date, you can change this by changing the mktime() return in dmytoMk().
    PHP Code:
    function dmytoMk($date) {
      
    $date explode("/",$date);
      return 
    mktime(000$date[0], $date[1], 0);
    }
    $arr = array('03/01/09','02/07/01','03/01/31');
    foreach(
    $arr as $key => $value){
      
    $arr[$key] = date("md"dmytoMk($value))." - "$value;
    }
    sort($arr);
    echo 
    implode("<br>",$arr); 
    It doesn't organize by year because:
    1) It would be harder
    2) I assume your already putting the events in the proper year.

    You need the first value that may look like: 0301, but after you sort($arr) you can remove it with maybe a strreplace, or an explode.
    Jeremy | jfein.net

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Thanks for that, but with me being not so great at this - how can I translate this into putting the <a name="jan"> anchor dynamically after it finds the first event in that month. Here is a link to the site so you have more of an understanding of what I'm on about.

    Click here

  7. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here ya go:
    PHP Code:
    function dmytoMk($date) {
      
    $date explode("/",$date);
      return 
    mktime(000$date[0], $date[1], 0);
    }
    $arr = array('12/01/09','02/07/01','05/01/31');
    foreach(
    $arr as $key => $value){
      
    $arr[$key] = date("md"dmytoMk($value))." || ".date("M"dmytoMk($value));
    }
    sort($arr);
    $month = array();
    $output "";
    for(
    $i=0;$i<count($arr);++$i){
      
    $month[] = explode(" || "$arr[$i]);
      
    $output .= "<a name=\"{$month[$i][1]}\">{$var}</a>";
    }
    echo 
    $str
    I guess you can put that all in one function so you don't have to do that every page - unless you're using while().
    Last edited by Nile; 01-30-2009 at 08:31 PM.
    Jeremy | jfein.net

  8. The Following User Says Thank You to Nile For This Useful Post:

    Schmoopy (01-30-2009)

  9. #8
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ah great, thanks for that

  10. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Glad to help you Schmoopy!
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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