59 users online (0 members and 59 guests)  

Thread: order by date


  Results 1 to 11 of 11

Related

  1. What would you do in order to be famous?    Forum: General Discussion
    Replies: 6
  2. jmail /asp sort order    Forum: ASP Forum
    Replies: 0
  3. Page rendering order?    Forum: General Discussion
    Replies: 0
  4. php data order    Forum: PHP Forum
    Replies: 1
  5. Replies: 7
  1. #1
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Lightbulb order by date

    i figured i'd ask about how to do this before i tried some backward way of doing this...

    so i'm working on an events page for a band website that lists events like this:


    06.22.05 Atlanta, GA @ Under the Couch. with Cursive, No Knife, and Thursday 7pm, 18+, FREE

    11.19.05 Knoxville, TN @ the Electric Ballroom. with Faraquet and Fugazi 8pm, all ages, $6

    01.03.06 Lousville, KY @ the Hell House. with The Red Scare, New Brutalisum, and Thumbnail 9pm


    ...ok here's how i was thinking about doing this.

    <select name=month id=month> options 1-12
    <select name=day id=day> options 1-31
    <select name=year id=year> options current year & next year
    <input name=details id=details>

    all three date inputs will be numberical, and the details will vary from show to show. currently i'm writing each show to a file... one show per line, like this:

    $month|$day|$year|$details

    ...then, reading the file with file(), and printing each line.

    the problem is that the the shows have to be written in the order that they need to be displayed. i'd rather not worry about the order in which the shows are written, and just order the show by their dates when they're displayed.

    any ideas on how to order the dates and display the corresponding details?
    robert koons

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: order by date

    Hiya,

    As the file() function loads the data into an array, it would make sense to try and use the array sort() function.

    Try

    Code:
    $data = file('data.file');
    sort($data);
    reset($data);
    This should sort from highest to lowest. Try it and let me know if it works.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: order by date

    i looked up sort() on php.net, and it needs to have the info in an array, which i wasn't using.

    Code:
    $shows = "./data/shows.txt";
    $read_shows=file("$shows") or die ('could not read file');
    foreach($read_shows as $line) 
    {
    list($order, $year, $month, $day, $details) = explode("|", $line);  
    echo "$month.$day.$year $details <br>";
    }
    i'm not sure how to put all the pieces together...

    Code:
    $shows = "./data/shows.txt";
    $read_shows=file("$shows") or die ('could not read file');
    foreach($read_shows as $line) 
    {
    list($order, $year, $month, $day, $details) = explode("|", $line);  
    
    $info = array($order, year, $month, $day, $details);
    
    sort($info);
    
    echo "$month.$day.$year $details <br>";
    
    reset($info);
    }
    is that even close?
    robert koons

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: order by date

    Look up file(), you'll see that the file is read into an array. Thats the array you need to sort. So sort $read_shows instead of $info.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: order by date

    ahaa... i've been using file() alot lately in various projects, but totally forgot that that's what makes it different from readfile().

    thanks dean!
    robert koons

  6. #6
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: order by date

    Cool. Glad its working.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  7. #7
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: order by date

    got a little edit here...
    as of right now it sorts by the first variable (which happens to be $order), but what if i want to sort by $venue?
    robert koons

  8. #8
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: order by date

    You might be able to sort using array_multisort but this depends on the the array itself.

    if you can't figure it from the above link, then please paste the output of

    Code:
    <pre>
    <?php
    print_r($read_shows);
    ?>
    </pre>
    here and I can have a look.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  9. #9
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: order by date

    yea, i got a little lost... i'm not sure if i should still be using the foreach loop. anyway, here's the output:

    Code:
    Array
    (
        [0] => 20050612|2005|06|12|Fort Smith|AR|Heshers|
    
        [1] => 20050613|2005|06|13|Jonesboro|AR|Ghostown|
    
        [2] => 20050614|2005|06|14|Nashville|TN|Hair of the Dog|
    
        [3] => 20050615|2005|06|15|Knoxville|TN|Electric Ballroom|
    
        [4] => 20050616|2005|06|16|Greensboro|NC|Aces Basement|
    
        [5] => 20050617|2005|06|17|Harrisonburg|VA|Captain Tees|
    
        [6] => 20050618|2005|06|18|Erie|PA|Forward Hall|
    
        [7] => 20050619|2005|06|19|Cleveland|OH|The Grog Shop|with Eisley - get tickets -
    
    )
    robert koons

  10. #10
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: order by date

    Cool. I'm away from my PC at the moment at a friends house, using a mac and I cant even figure how to copy&paste so I'll get back on this tommorow night when I get in.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  11. #11
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: order by date

    hey dean, any luck on this?
    robert koons



Tags for this Thread