SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 29
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arranging Date information

    Sorry if this is more of a php question, rather than database, however im unsure what woud be the best practice.

    At the moment i have events. The actual events date/or dates are in stored in their own database (that refers to the event id).

    What i dont know how to do is this, if an event is for one day its quite simple to display, however if an event is on for 3 days (12th, 13th, 14th), how can i display the record as;

    '12th - 14th October' (the start and end date with a '-' in the middle)

    ......without adding a '-' in the html (as this would effect a event for one day looking something like '12th October - '

    Note; All the events need to have each date in the database so that they can be sent to the box office for processing.

    Many thanks in advance, and sorry if im not very clear!


    EDIT: ive just reposted this message from the database forum.

    Dan commented

    "This is display logic and belongs in your PHP code. If the number of rows for the event is greater than one, display the dates with a dash, else display only the date."

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    exactly what Dan said:
    PHP Code:
    $rows mysql_num_rows($query);
    if(
    $rows 1){
       echo 
    mysql_result($query0'Date') . " - " mysql_result($query$rows-1'Date');
    }else{
       echo 
    mysql_result($query0'Date');

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers...

    Ill have go in morning. ...i may be back intouch!

    Many thanks

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...what i didnt think about is that my php skills are very miminual, therefore i do use dreamweaver to populate.....therefore how would i intergrate your condition when using something like;

    <?php echo $row_Recordset1['eventdate']; ?>

    many thanks in advance

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can I see the code from the SQL statement itself, upto after the while() code block (where it loops through all results)?

    Also, how are multi-day events listed in your database table? I'm guessing that for each day, theres a different record. Am I correct?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi...im going to 'try' and do the recordset statement this afternoon.

    With reference to the database tables...i was thinking about having a date/time in each line, that will have a id that refers to its applicable event...

    So from the main cms, ill add an event (into the event table), then add dates/times (into the dates table) with an eventid. Then when i pull the records together ill use where eventID equals dateID.

    .....well, thats the theory!

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Can I see the code from the SQL statement itself, upto after the while() code block (where it loops through all results)?

    Also, how are multi-day events listed in your database table? I'm guessing that for each day, theres a different record. Am I correct?
    Good afternoon...as mentioned all the event dates are added separatley and are brought together via the event id.

    Ruby has helped my do the sql statement, as;

    Code:
    SELECT e.id as Event
         , e.title
         , e.imageS
         , e.text
         , min(ed.eventdate) as mindate
         , max(ed.eventdate) as maxdate
      FROM events e       
    INNER 
      JOIN eventdates ed 
        ON ed.eventid = e.id
    GROUP
        BY e.id
    ORDER 
        BY e.title
    Now i use (dont shoot me down) dreamweaver...So what ive simply done is drag and drop into the html
    Code:
    <p><?php echo $row_Recordset2['mindate']; ?> <?php echo $row_Recordset2['maxdate']; ?></p>
    As my php hard coding is rather crap, can this just be tweeked, or do i need to rewrite the dreameaver recordset with php?

    b

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    it's rudy -- i'm a guy
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah....over the last fews days i had visions of what you looked like...now its all gone out of thew window!

  11. #11
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    erm... ok...
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #12
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    erm... ok...
    i wrote about rudy, not you...dont worry

    Can you help me?

  13. #13
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I know...

    Anyway, this could help:
    PHP Code:
    <?
    echo "<p>".$row_Recordset2['mindate'] . (($row_Recordset2['maxdate'] > $row_Recordset2['mindate']) ? " - ".$row_Recordset2['maxdate'] : "")."</p>";
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    or, more readably:
    PHP Code:
    $min $row_Recordset2['mindate'];
    $max $row_Recordset2['maxdate'];
    printf("<p>%s%s</p>"$min, (($max $min) ? " - " $max "")); 
    and if the dates aren't in number format:
    PHP Code:
    $min strtotime($row_Recordset2['mindate']);
    $max strtotime($row_Recordset2['maxdate']);
    printf("<p>%s%s</p>"$min, (($max $min) ? " - " $max "")); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #15
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    and, if you want it in date format:
    PHP Code:
    $min $row_Recordset2['mindate'];
    $max $row_Recordset2['maxdate'];
    printf("<p>%s%s</p>"$min, ((strtotime($max) > strtotime($min)) ? " - " $max "")); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  16. #16
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers,

    I Initaly used your first version, but i thought what the heck, lets try something differant and used

    Code:
    $min = $row_Recordset2['mindate'];
    
    $max = $row_Recordset2['maxdate'];
    
    printf("<p>%s%s</p>", $min, ((strtotime($max) > strtotime($min)) ? " - " . $max : ""));
    is it possible to format the date i.e 'saturday 12 september' via php, or will this need to be done via the inital sql statement?

  17. #17
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you can use it like this:
    PHP Code:
    $dateformat "l jS F, y"
    $min $row_Recordset2['mindate'];
    $minform date($dateformat$min);
    $max $row_Recordset2['maxdate'];
    $maxform date($dateformat$max);
    printf("<p>%s%s</p>"$minform, ((strtotime($max) > strtotime($min)) ? " - " $maxform "")); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  18. #18
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i just used;

    Code:
    <?php
    $dateformat = "l jS F, y"
    $min = $row_Recordset2['mindate'];
    $minform = date($dateformat, $min);
    $max = $row_Recordset2['maxdate'];
    $maxform = date($dateformat, $max);
    printf("<p>%s%s</p>", $minform, ((strtotime($max) > strtotime($min)) ? " - " . $maxform : "")); ?>
    and got Parse error: syntax error, unexpected T_VARIABLE in H:\wampfinal\www\albany\masterpage.php on line 490

    which is the second line of

    Code:
    $dateformat = "l jS F, y"
    $min = $row_Recordset2['mindate'];

  19. #19
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah it was just missing the ';'

  20. #20
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ah, oops.

    Theres a list of the different things you can do with the $dateformat string at http://uk.php.net/date.

    It's definately worth bookmarking, especially for offline use.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  21. #21
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh...how rude of me...thanks very much for your help, it works like a dream!

    b

  22. #22
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, i just realised.....the script below just shows the first date in the table, therefore each event has the same date.

    Quote Originally Posted by arkinstall View Post
    you can use it like this:
    PHP Code:
    $dateformat "l jS F, y"
    $min $row_Recordset2['mindate'];
    $minform date($dateformat$min);
    $max $row_Recordset2['maxdate'];
    $maxform date($dateformat$max);
    printf("<p>%s%s</p>"$minform, ((strtotime($max) > strtotime($min)) ? " - " $maxform "")); 
    whereas using this script, it works, but i dont like the date format...

    Code:
    $min = $row_Recordset2['mindate'];
    
    $max = $row_Recordset2['maxdate'];
    
    printf("<p>%s%s</p>", $min, (($max > $min) ? " - " . $max : "")); ?>

  23. #23
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ah - try this:
    PHP Code:
     $dateformat "l jS F, y";
    $min $row_Recordset2['mindate'];
    $minform date($dateformat$min);
    $max $row_Recordset2['maxdate'];
    $maxform date($dateformat$max);
    printf("<p>%s%s</p>"$minform, (($max $min) ? " - " $maxform "")); 
    I shouldn't have left the strtotime() in there.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  24. #24
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hum...still showing the same date for each record....

  25. #25
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    can I see some sample data?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •