Jump to content

mysql sorting buttons. very confused


xtjx09

Recommended Posts

okay so what i need is for my table header to sort by size, then if clicked again, change back to how it was. i think something is just wrong with my query. please help.

 

<?php
session_start();
$user = $_SESSION["name"];

		mysql_connect("server", "soemthing", "sopmething");;
	@mysql_select_db("something") or die("Unable to connect to database.");

	      if (isset($_GET["id"]))
      {
            $id=$_GET["id"];
            $query="select filename, type, size, content from $user where id = '$id'";
            $result=mysql_query($query);
            list($filename, $type, $size, $content)=mysql_fetch_array($result);
            header("Content-length: $size");
            header("Content-type: $type");
            header("Content-Disposition: attachment; filename=$filename");
            echo $content;
            exit;
      }
     
      
?>
      
<html>
<head>
	<title>Download</title>
</head>
<body>

<div>
	<?php
			if(isset($_GET['sort']))
			{
				$sort = $_GET['sort'];
				echo $sort;
				$space = " ";

				if (isset($_GET['way']))
					{
						$way= $_GET['way'];
						echo $way;
					}
			}


		if(isset($_GET['sort']) && (isset($_GET['way'])))
      {
      $select = mysql_query("select * from $user ORDER BY" .$sort.$way);
    						
      }
      else
      $select = mysql_query("select * from $user");
     
    	

	//new


		if (mysql_num_rows($select)==0)
		{
			echo "There is nothing to download<br />";
		}

		else
		{
	?> 
<table border = 1px;>
	<tr>
	<form method= "get" action= "">
		<th><a href = "test.php?sort=asc"> File Name </a></th>
		<th><input type= "submit" name= "sorttype" value= "File Type"></th>
		<th><a href = "test.php?sort=size&way=asc">size</a></th>
		<th><input type= "submit" name= "sortdesc" value= "Description"></th>
	</form>
	</tr>

	<form method = "post">
		<?php
	while (list($id, $filename, $type, $size, $content, $description, $number)=mysql_fetch_array($select))
		{
	?>
		<tr>

			<td><a href="download.php?id=<?php echo $id;?>"><?php echo $filename;?></a></td>
			<td><?php echo $type;?></td>
			<td><?php echo $size;?></td>
			<td> <?php echo $description; ?> </td>

		</tr>
	<?php
	}
}
?>

</div>


</body>
</html>




[code]

Link to comment
https://forums.phpfreaks.com/topic/150530-mysql-sorting-buttons-very-confused/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.