Home  >  Article  >  Backend Development  >  关于order by有关问题

关于order by有关问题

WBOY
WBOYOriginal
2016-06-13 12:49:501011browse

关于order by问题
类似这种的

比如说www.xxx.com/index.php?id=5&order=zhucetime

$order=$_GET['order'];
$id=$_GET['id'];


$sqltext="select * from table where n_pid='".$id."'  order by '".$order."'  asc";
 




如何实现第一次点击的时候是按asc排序   第二次点击后是按照desc排序 不断的循环切换啊?

如何实现第一次点击的时候是按asc排序   第二次点击后是按照desc排序 不断的循环切换啊?


------解决方案--------------------
<br />
if(!isset($_SESSION['direction']) <br><font color='#FF8000'>------解决方案--------------------</font><br> $_SESSION['direction'] == 'desc')<br />
{<br />
   $_SESSION['direction'] = 'asc';<br />
}<br />
else<br />
{<br />
   $_SESSION['direction'] = 'desc';<br />
}<br />
<br />
$sql = "select * from table where n_pid='".$id."'  order by  ".$order."  ".$_SESSION['direction'];<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn