redirecting back to php file

Posted by tooepic on Stack Overflow See other posts from Stack Overflow or by tooepic
Published on 2010-04-13T03:21:53Z Indexed on 2010/04/13 3:22 UTC
Read the original article Hit count: 406

Filed under:

hello again,

following code is my php file that will list the people in my text file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>viewlist php</title>
</head>
<body>
<h1>List</h1>
<?php
$file = file("peoplelist.txt");
for($i=0; $i<count($file); $i++)
{
  $person = explode(",", $file[$i]);
  echo "<hr />";
  echo "<table cellspacing=10><tr><td>", $i+1,".", "</td>";
  echo "<td>", $person[0], "<br />";
  echo $person[1], "</td></tr></table>";
}
?>
<hr />
<p>
  <a href="sortatoz.php" target="_self">Sort A-Z</a><br />
  <a href="sortztoa.php" target="_self">Sort Z-A</a><br />
</p>
</body>
</html>

what i want to do is, when i click Sort A-Z link, the file called sortatoz.php will sort the list in my text file and redirect back to viewlist.php with the list in sort order. below is my sortatoz.php:

<?php
header("Location: http://myserver/workspace/viewlist.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>sort a to z</title>
</head>
<h1>List</h1>
<body>
<?php
$file = file("peoplelist.txt");
sort($file);
for($i=0; $i<count($file); $i++)
{
  $person = explode(",", $file[$i]);
  echo "<hr />";
  echo "<table cellspacing=10><tr><td>", $i+1,".", "</td>";
  echo "<td>", $person[0], "<br />";
  echo $person[1], "</td></tr></table>";
}
?>
<hr />
<p>
  <a href="sortvisitorsascending.php" target="_self">Sort Visitors A-Z</a><br />
  <a href="sortvisitorsdescending.php" target="_self">Sort Visitors Z-A</a><br />
</p>
</body>
</html>

now, when i click Sort A-Z link, it redirects back to viewlist.php...so I'm assuming the header() function is doing it's job.

but the problem is...it's not sorting.

i am very new with this, so bear with me and give me some guidance please. what can i do to my codes to redirect back viewlist.php with sorted list?

thanks in advance.

© Stack Overflow or respective owner

Related posts about php