Page 1 of 1

Asc and desc of table

Posted: Tue Jul 31, 2007 10:24 pm
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]

Posted: Tue Jul 31, 2007 10:37 pm
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.

Asc and desc

Posted: Tue Jul 31, 2007 11:07 pm
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]

Posted: Tue Jul 31, 2007 11:30 pm
by feyd

Code: Select all

is not proper syntax tags for php. 

Look carefully at your if statements' expressions.