SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 15th, 2002, 09:15 AM
Treetaliano Treetaliano is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Florence, Italy
Posts: 4 Treetaliano User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Treetaliano
Alphabetical order? Help!

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:pathtoconfig.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>

so aftter looking around a bit in the manual, I see this:

<?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:pathtoconfig.php");

$fd = fopen ($teams, "r");
while (!feof ($fd))
{
$readlines = fgets($fd, 4096);
$squads = explode("|", $readlines);
$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>


I still get the same result as before.
What am I doing wrong??

Thanks again

-Tree

Reply With Quote
  #2  
Old September 15th, 2002, 11:14 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Alphabetical order? Help!

i think it'd be much easier for you if you created a multi-demensional array as follows, and then had a look at the multi-sort function.
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. include("C:pathtoconfig.php");
  5.  
  6. $lines = file("$teams");
  7. for($i=0; $i<count($lines); $i++)
  8. {
  9.     $squads[$i] = explode("|", $lines[$i]);
  10. }
  11.  
  12. // now $squads[0][0] = 1st id
  13. // $squads[0][1] = 1st title
  14. // $squads[1][0] = 2nd id etc..
  15.  
  16. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Alphabetical order? Help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway