TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   How do you set a List in Alphabetical Order? (http://www.talkphp.com/general/1777-how-do-you-set-list-alphabetical-order.html)

Orc 12-20-2007 03:34 AM

How do you set a List in Alphabetical Order?
 
Such as a long list of things?

Village Idiot 12-20-2007 03:46 AM

What is your data source?

Aaron 12-20-2007 03:49 AM

Something like this might work...
$var = strtolower($var);
if (isset($vars[$var])) {
$vars[$var]++;
} else {
$vars[$var] = 1;
}



buuuuut, I think this would be a built in function... Lemme check the documentation.


edit: Yeah, look here for some nice information... I think...

http://nl3.php.net/manual/hu/function.strcmp.php

Orc 12-20-2007 03:49 AM

Quote:

Originally Posted by Village Idiot (Post 6899)
What is your data source?

You mean my source? or just..? I want to use strings, not arrays!

Village Idiot 12-20-2007 03:50 AM

Is it a collection of strings in an array? Is it from a mysql database?

Orc 12-20-2007 03:51 AM

Quote:

Originally Posted by Village Idiot (Post 6902)
Is it a collection of strings in an array? Is it from a mysql database?

No, it's a directory script. using the Dir class.

Village Idiot 12-20-2007 03:54 AM

But how are the strings stored? I cant help you until I know that.

Orc 12-20-2007 03:59 AM

Quote:

Originally Posted by Village Idiot (Post 6904)
But how are the strings stored? I cant help you until I know that.

PHP Code:

<?php 

$dir 
dir$d );
  while( 
false !== ( $entry $dir->read() ) ) {
if(
$entry!='.' && $entry!='..' && $entry!='index.php' && $entry!='error_log') {



   echo 
'<b><a style="color:red;font-family:helvetica;font-size:12px;" href="'.$entry.'">';
   print 
$entry.'<br/>';
   echo 
'</a></b>';

 }
}



     

?>


Village Idiot 12-20-2007 04:11 AM

Something like this
PHP Code:

 <?php  

$dir 
dir$d ); 
  while( 
false !== ( $entry $dir->read() ) ) { 
if(
$entry!='.' && $entry!='..' && $entry!='index.php' && $entry!='error_log') { 



$arr[] = $entry;

 } 


sort($arr); //making your own bubble sort method will be faster, but I cant find mine
foreach($arr as $val)
{
echo 
$val;
}


      

?>


Orc 12-20-2007 04:41 AM

Quote:

Originally Posted by Village Idiot (Post 6906)
Something like this
PHP Code:

 <?php  

$dir 
dir$d ); 
  while( 
false !== ( $entry $dir->read() ) ) { 
if(
$entry!='.' && $entry!='..' && $entry!='index.php' && $entry!='error_log') { 



$arr[] = $entry;

 } 


sort($arr); //making your own bubble sort method will be faster, but I cant find mine
foreach($arr as $val)
{
echo 
$val;
}


      

?>


Okay I just tried that and I got
Code:

Parse error: syntax error, unexpected ')' in index.php on line 47

Village Idiot 12-20-2007 04:43 AM

Whats line 47. I have to go now, il be back tomorrow afternoon

Orc 12-20-2007 04:46 AM

Quote:

Originally Posted by Village Idiot (Post 6911)
Whats line 47. I have to go now, il be back tomorrow afternoon

-snip- Nevermind I think I got it, my mistake! >.<


All times are GMT. The time now is 04:23 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0