Jump to content

Recommended Posts

How to sort in ascending and descending order for the particular column when clicked on header......

The data is fetched from files

 

 

$id = $_GET['id']; 

$lines = file('phonedb.txt'); 

echo "<ul id=\"containerul\"><li class=\"connection\">View Tree"; 


echo "<ul><li class=\"connection\"><a href=\"tree.php?id=name\">Name</a>"; 

echo "<ul>"; 

for($i=0;$i<sizeof($text_array); $i++) { 

echo "<li>--".$text_array[$i]['name']."</li>"; 
} 

echo "</ul></li>"; 



echo "<li class=\"connection\"><a href=\"tree.php?id=address\">Address</a>"; 
echo "<ul>"; 
for($i=0;$i<sizeof($text_array); $i++) { 
echo "<li>--".$text_array[$i]['address']."</li>"; 
} 

echo "</ul></li>";

Link to comment
https://forums.phpfreaks.com/topic/62778-asc-and-desc-for-column/
Share on other sites

You can sort using helper functions, like this:

 

function cmp_name($a, $b) {
  return stricmp($a['name'], $b['name']);
}
usort($array, 'cmp_name');

 

This particular comparison function does a case insensitive comparison of the names in the array, and sorts in that order.

Hi,

 

I just want how to sort the column without multisort....

Individual column I should sort...

But if I use the code in this way

 

 

 

<?php 
$id = $_GET['id']; 

echo "<html>"; 
echo "<body bgcolor=\"#FFF0FF\" text=\"#000000\">"; 
$lines = file('phonedb.txt'); 
echo "<ul id=\"containerul\"><li class=\"connection\">View Tree"; 


echo "<ul><li class=\"connection\"><a href=\"tree.php?id=name\">Name</a>"; 

echo "<ul>"; 
if($id=="") 
{ 


foreach($lines as $line) 
{ 
$text_line=explode(":",$line); 
echo "<li>--$text_line[0]</li>"; 
} 
} 
if($id="name") 
{ 
sort($lines); 
foreach($lines as $line) 
{ 
$text_line=explode(":",$line); 
$text=explode(" ",$text_line[0]); 
for($i=0;$i<count($text);$i++) { 
echo "<li>--$text[$i]</li>"; 
} 
} 
} 
echo "</ul></li>"; 

echo "<li class=\"connection\"><a href=\"tree.php?id=address\">Address</a>"; 
echo "<ul>"; 
if($id=="") 
{ 
foreach($lines as $line) 
{ 
$text_line=explode(":",$line); 
echo "<li>--$text_line[1]</li>"; 
} 
} 
if($id="address") 
{ 
sort($lines); 
foreach($lines as $line) 
{ 
$text_line=explode(":",$line); 
$text=explode(" ",$text_line[1]); 
for($i=0;$i<count($text);$i++) { 
echo "<li>--$text[$i]</li>"; 
} 
} 
} 
?> 

I am not able to sort the particular column

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.