Thread: order by date
Results 1 to 11 of 11
Related
-
What would you do in order to be famous? Forum: General Discussion
Replies: 6 -
jmail /asp sort order Forum: ASP Forum
Replies: 0 -
Page rendering order? Forum: General Discussion
Replies: 0 -
php data order Forum: PHP Forum
Replies: 1 -
Does the order of properties in CSS matter? Forum: CSS Forum
Replies: 7
-
05-26-2005, 08:00 PM #1
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
-
05-27-2005, 04:33 AM #2
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);
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
05-27-2005, 09:26 AM #3
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>"; }
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); }
robert koons
-
05-27-2005, 09:33 AM #4
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 theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
05-27-2005, 09:43 AM #5
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
-
05-27-2005, 09:48 AM #6
Re: order by date
Cool. Glad its working.
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
06-16-2005, 03:43 PM #7
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
-
06-17-2005, 06:08 AM #8
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>
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
06-17-2005, 08:05 AM #9
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
-
06-18-2005, 04:38 PM #10
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 theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
06-29-2005, 02:27 PM #11
Re: order by date
hey dean, any luck on this?
robert koons
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum