Skip to content
WJunction - Webmaster Forum

jquery advanced sorting question

Status
Not open for further replies.
Hi !
I am having problem doing this in php thats why my last hope is jquery.

Ok here's the problem :
I need to sort everything based on numbers.
I am amateur in Jquery so please give some script.

CURRENT:
Code:
<div id=incase>
<span class=top_ten_fav id=0>something[I](has numbers)[/I] (<span class=0>2</span>).</span><br />
<span class=top_ten_fav id=1>something[I](has numbers)[/I] (<span class=1>1</span>).</span><br />
<span class=top_ten_fav id=2>something[I](has numbers)[/I] (<span class=2>1</span>).</span><br />
<span class=top_ten_fav id=3>something[I](has numbers)[/I] (<span class=3>1</span>).</span><br />
<span class=top_ten_fav id=4>something[I](has numbers)[/I] (<span class=4>1</span>).</span><br />
<span class=top_ten_fav id=5>something[I](has numbers)[/I] (<span class=5>1</span>).</span><br />
<span class=top_ten_fav id=6>something[I](has numbers)[/I] (<span class=6>1</span>).</span><br />
<span class=top_ten_fav id=7>something[I](has numbers)[/I] (<span class=7>1</span>).</span><br />
<span class=top_ten_fav id=8>something[I](has numbers)[/I] (<span class=8>1</span>).</span><br />
<span class=top_ten_fav id=9>something[I](has numbers)[/I] (<span class=9>14</span>).</span><br />
<span class=top_ten_fav id=10>something[I](has numbers)[/I] (<span class=10>28</span>).</span><br />
<span class=top_ten_fav id=11>something[I](has numbers)[/I] (<span class=11>15</span>).</span><br />
<span class=top_ten_fav id=12>something[I](has numbers)[/I] (<span class=12>1</span>).</span><br /></div>

AND MORE...

OUTPUT NEEDED :
Code:
something[I](has numbers)[/I] (28).
something[I](has numbers)[/I] (15).
something[I](has numbers)[/I] (14).
something[I](has numbers)[/I] (2).
something[I](has numbers)[/I] (1).
something[I](has numbers)[/I] (1).
something[I](has numbers)[/I] (1).
something[I](has numbers)[/I] (1).
something[I](has numbers)[/I] (1).
something[I](has numbers)[/I] (1).

Classes and Ids are all editable(i just gave numbers to them so they can help?).

Pls help that's damn important (i lost 12 hours on pc about this) :(
 

6 comments

each something is different

here's the php code !

PHP:
function directoryToArray($directory, $recursive) {
	$array_items = array();
	if ($handle = opendir($directory)) {
		while (false !== ($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				if (is_dir($directory. "/" . $file)) {
					if($recursive) {
						$array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
					}
					$file = $directory . "/" . $file;
					$array_items[] = preg_replace("/\/\//si", "/", $file);
				} else {
					$file = $directory . "/" . $file;
					$array_items[] = preg_replace("/\/\//si", "/", $file);
				}
			}
		}
		closedir($handle);
	}
	return $array_items;
}

$filenamesdl=directoryToArray('fav',true);

$filenames = array();
while (list ($key, $val) = each ($filenamesdl)) { 
if(strstr($val,".txt")){
$filenames[]=basename($val); }
}

$filenames=array_count_values($filenames);


$total = array();
while (list ($key2, $val2) = each ($filenames)) { 
$total[]=$val2;
}


$i=0;
foreach ($filenamesdl as $dl) {
$filenamesdl=@file_get_contents($dl);
if(!empty($filenamesdl) && !empty($total[$i])){
$entry_arrayz[ 'entry' ]  .=  '<span class=top_ten_fav id='.$i.'>'.$filenamesdl . '(<span class='.$i.'>'.$total[$i].'</span>).</span><br />';
     $i++;
	 } }
$entry_arrayz[ 'entry' ]="<div id=incase>".$entry_arrayz[ 'entry' ].'</div>';

The php script downloads all .txt files in a directory (+subdirs) and counts the filenames(array_count_values).
So i must sort the downloaded txt with the array_count_values.
 
Last edited:
@JmZ
woow man ! You just discovered new jquery function which i bet many people will use ! It is equal to natsort in php ! So many tnx ! I wish i had a paypal to pay you a beer :p

Btw how to limit the results to ten ?
 
=)
Finally. I feel bit relaxed cuz the only thing left to do is to make delete/edit functions to my custom forum :)

JQuery is so powerful and it has future !
TNX !
 
Status
Not open for further replies.

About the author

Porsche_maniak
Established Member · Joined
Auto racing,Porsche,Web Development
283
Messages
0
Reactions
16
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom