Asc and desc of table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Asc and desc of table

Post by sandy1028 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


How to sort in ascending and descending order for the particular column when clicked on header...... 
The data is fetched from files

Code: Select all

$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>";

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

array_multisort()/usort() or some variant thereof.

On a side note: I believe I've edited enough of your posts now. Please start using the proper syntax tags immediately.
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Asc and desc

Post by sandy1028 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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

Code: Select all

<?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

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

is not proper syntax tags for php. 

Look carefully at your if statements' expressions.
Post Reply