Re: alphabetical order?
| From: | Sascha Cunz | Date: | Sun, 15 Sep 2002 16:14:02 +0000 |
| Subject: | Re: alphabetical order? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116442@lists.php.net to get a copy of this message | ||
You need to read the file completely, then sort it, finally output it.
You should have a look at:
For reading:
http://www.php.net/manual/en/function.array-push.php
For Sorting:
http://www.php.net/manual/en/function.usort.php
(Example 2)
For output:
http://www.php.net/manual/en/function.each.php
(Example 2)
Sascha
Am Sonntag, 15. September 2002 11:23 schrieb Chad Winger:
> That doesnt really explain much to me unfortunately :(
>
> here is what I see in the manual
>
> <?php
>
> $order = array ($squads[1]);
> sort ($order);
> reset ($order);
> while (list ($key, $val) = each ($order)) {
> echo "order[".$key."] = ".$val."\n";
>
>
> ?>
>
> so the array $order is declared, then is sorted. To me that means that I
> have to declare each fruit in the array. In my array $squads in the example
> below [0] is id number [1] is team name [2] is stadium and [4] is city. I
> want to alphabatize only the team name i.e. $squads[1] then after the team
> name is alphabatized (sorted) then the if...else statement is run ... so
> this is what i tried
>
> <html>
> <body>
> <select>
> <?php
>
> include ("C:\Program
> Files\EasyPHP\www\florentiaviola.com\control\config.php");
>
> $fd = fopen ($teams, "r");
> while (!feof ($fd))
> {
> $buffer = fgets($fd, 4096);
> $squads = explode("|", $buffer);
> $order = array ($squads[1]);
> sort ($order);
> reset ($order);
> while (list ($key, $val) = each ($order)) {
> if ($squads[1] == "Florentia Viola") {
> echo '<OPTION SELECTED VALUE="'.$squads[0].'">Florentia
> Viola</OPTION>'."\n";
> } else {
> echo '<OPTION
> VALUE="'.$squads[0].'">'.$squads[1].'</OPTION>'."\n";
> }
> }
>
> }
> fclose ($fd);
>
> ?>
> </html>
> </body>
> </select>
>
>
> What am I doing wrong??
>
> Thanks again
>
> -Tree
>
>
>
>
>
>
>
>
>
>
> Jeremy Wilson <jwilson@intravative.com> wrote in message
> news:000201c25c89$ec2b70a0$4ac23342@intravative.com...
>
> > This will also help you
> >
> > http://www.php.net/manual/en/function.array-multisort.php
> >
> > -----Original Message-----
> > From: Chad Winger [mailto:cwinger@callistonet.com]
> > Sent: Saturday, September 14, 2002 11:57 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] alphabetical order?
> >
> >
> > If you've read some of my earlier posts, you know I'm a newbie at PHP,
> > so now im stuck at a point, and I'd like to see if anyone has a
> > suggestion. Ok, here is the problem...i have a text file on the server,
> > and in it are listed lines like this:
> >
> > 01|Brescello|stadium|city|
> > 02|Aglianese|stadium|city|
> > 03|Casteldisangro|stadium|city|
> >
> > and the following code is part of a php file that creates a form.
> >
> > <SELECT NAME="home">
> > <?php
> >
> > include ("C:\path\to\config.php");
> >
> > $fd = fopen ($teams, "r");
> > while (!feof ($fd))
> > {
> > $readlines = fgets($fd, 4096);
> > $squads = explode("|", $readlines);
> > if ($squads[1] == "Florentia Viola") {
> > echo '<OPTION SELECTED
> > VALUE="'.$squads[0].'">Florentia
> > Viola</OPTION>'."\n";
> > } else {
> > echo '<OPTION
> > VALUE="'.$squads[0].'">'.$squads[1].'</OPTION>'."\n";
> > }
> >
> > }
> > fclose ($fd);
> >
> > ?>
> > </SELECT>
> >
> > What is does is create options in a dropdown menu. Right now the
> > outputted HTML would be
> >
> > <OPTION>Brescello</OPTION>
> > <OPTION>Aglianese</OPTION>
> > <OPTION>Casteldisangro</OPTION>
> >
> > Problem is that I would like it alphabatized, like so:
> >
> > <OPTION>Aglianese</OPTION>
> > <OPTION>Brescello</OPTION>
> > <OPTION>Casteldisangro</OPTION>
> >
> > I've done pretty well I think in the few days, i've tried learning this
> > stuff. but i have no idea on where to begin with this problem.
> >
> > ALso, as Im still pretty much a PHP infant, if anyone sees any little
> > things with my code that code be better (i.e. a way to simplify it etc)
> > let me know. Thanks I appreciate it
> >
> > -Tree
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php