Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help to sort folders alphabetically
Old 11-14-2009, 12:10 PM Help to sort folders alphabetically
Junior Talker

Posts: 1
Trades: 0
hi,
in this code "Virtual Directories" and "Files" are sort alphabetically, but i don't know how to sort "Non Virtual Directories" ???
Thanks for your help and sorry for my bad english !

Code:
	// For Virtual Directories
	if($path == '' || $path == '/'){

		$query = sprintf('select * from %spermissions inner join %sbins on %spermissions.binid=%sbins.id where userid="%s" and %sbins.name ="%s" order by display',
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$_SESSION['userid'],
						$GLOBALS['tablePrefix'],
						$_SESSION['user']);
						
		$result = mysql_query($query,$database) or die( error('Get Folder query failed') );
		
		while($bins = mysql_fetch_assoc($result)) {
			$listing[] = array(  displayname => $bins['display'],
										scheme => $bins['scheme'],
										type => "directory",
										name => $bins['name'],
										path => '/'. $bins['name'],
										virtual => "true" );
		}				
			
		$query = sprintf('select * from %spermissions inner join %sbins on %spermissions.binid=%sbins.id where userid="%s" and %sbins.name !="%s" order by display',
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$GLOBALS['tablePrefix'],
						$_SESSION['userid'],
						$GLOBALS['tablePrefix'],
						$_SESSION['user']);
						
		$result = mysql_query($query, $database) or die( error('Get Folder query failed') );
		$vdcount = mysql_num_rows($result);
		
		switch(true) {
			case ($vdcount >= 1):
				$virtual = "closed";
				break;
			case ($vdcount == 1):
				$virtual = "true";
				break;
			default :
				$virtual = "false";
		}
		
		if($vdcount > 0)
			while($bins = mysql_fetch_assoc($result)){
				$listing[] = array(  displayname => $bins['display'],
											scheme => $bins['scheme'],
											type => "directory",
											name => $bins['name'],
											path => '/'. $bins['name'],
											virtual => $virtual );
			}
			
		echo $json->encode($listing);
		exit;
	}


	// Non Virtual Directories
	if( getUserAuth('view', $path) ){
		logAction('list',$path);
		$fullpath = getUserPath($path).$path;
		databaseSync($fullpath,$path);
		
		// Directories
		if (is_dir($fullpath)) {
			if ($dh = opendir($fullpath)) {
			   while (($file = readdir($dh)) !== false) {
			     if(substr($file,0,1) != '.' && is_dir($fullpath . '/' . $file)) {
						$listing[] = array( 
									type => "directory", 
									name => $file, 
									path => $path .'/'. $file );
				  }
			   }
			   closedir($dh);
			}
		}
		else error("directory doesnt exist $fullpath");

		// Files
		$query = sprintf('select *,date_format(`date`,"%s") as `dateformatted` from %sfilesystem where path="%s" and status="%s" order by `filename',
								$dateFormat,
								$GLOBALS['tablePrefix'],
								$fullpath,
								"found" );
								
		$result = mysql_query($query,$database) or die( error('Get Folder query failed') );
		while($files = mysql_fetch_assoc($result)) {
			$listing[] = array(	type => "file",
										name => $files['filename'],
										date => $files['dateformatted'],
										id => $files['id'] );
		}
	      
	}
	else error("Access Denied $path");
	
	echo $json->encode($listing);
	exit;
}
Attached Images
File Type: jpg sort.jpg (14.1 KB, 3 views)

Last edited by 100tral; 11-14-2009 at 12:12 PM..
100tral is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-17-2009, 12:55 PM Re: Help to sort folders alphabetically
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
Perhaps, asort() - http://www.php.net/manual/en/function.asort.php
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 11-19-2009, 09:19 AM Re: Help to sort folders alphabetically
Super Talker

Posts: 139
Name: John Davis
Trades: 0
It's hard to define your situation because of your image is too litle.
By the way, the order of folders is depends from OS settings.
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Reply     « Reply to Help to sort folders alphabetically
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12083 seconds with 13 queries