Sort

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
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Sort

Post by rash28 »

hi,

I have a problem in sorting. The sort is done for independently for each columns.
Problem is when the sort of Name is in ascending order and when I click on the Address header the sort of the Name column also changes to descending order.
Please help me with this. The sort order should not change unless I click on the particular header.







Code: Select all

$name = $_GET['name'];
$address = $_GET['address'];

$lines = file('phonedb.txt');
echo "<ul id=\"containerul\"><li class=\"connection\">View Tree";

if($name != "asc")
{
echo "<ul><li class=\"connection\"><a href=\"tree.php?name=asc\">Name</a>";
}
else if($name == "asc"){
echo "<ul><li class=\"connection\"><a href=\"tree.php?name=desc\">Name</a>";
}
echo "<ul>";

if($name == "asc")
{
$line1 = array();
foreach($lines as $line)
{
$text_line=explode(":",$line);
$line1[] = $text_line[0];
}
sort($line1);
for($i=0;$i<=count($line1);$i++){
$text_line=explode(":",$line);
echo "<li class=\"ToolText\" onMouseOver=\"javascript:this.className='ToolTextHover'\" onMouseOut=\"javascript:this.className='ToolText'\">--$text_line[0]<span>$tool</span></li>";

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


if($address != "asc")
{
echo "<ul><li class=\"connection\"><a href=\"tree.php?address=asc\">Address</a>";
}
else if($address == "asc"){
echo "<ul><li class=\"connection\"><a href=\"tree.php?address=desc\">Address</a>";
}
echo "<ul>";

if($address == "asc")
{
$line2 = array();
foreach($lines as $line)
{
$text_line=explode(":",$line);
$line1[] = $text_line[1];
}
sort($line2);
for($i=0;$i<=count($line2);$i++){
$text_line=explode(":",$line);
echo "<li class=\"ToolText\" onMouseOver=\"javascript:this.className='ToolTextHover'\" onMouseOut=\"javascript:this.className='ToolText'\">--$text_line[1]<span>$tool</span></li>";

}
}
echo "</ul></li>";
Last edited by rash28 on Mon Aug 06, 2007 6:03 am, edited 1 time in total.
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Pointer

Post by rash28 »

Hi,

When I click on the header of the table the pointer of mouse points to the top of the page.
How do I make it point to the location where the header is clicked
Post Reply