通过url控制数据排序

2012.12.18 No Comments

php代码

Wayde: 看代码

//数据连接

$con =  mysql_connect("localhsot","root","xxioo");
if(!$con)</li>
{die('Could not connect: '.mysql_error());}
mysql_select_db("my_db",$con);

//通过URL值排序

$order = ($GET['order']=='up')? 'asc' : 'desc';
$this-assign('order',$order);         //传给页面$order
$result = mysql_query("SELECT * FROM  Demo ORDER BY  id  ".$order);
$this->assign('result', $result );

<strong><span style="color: #ff0000;">html代码</span></strong>

<a href="action.php?order="<if condition="$order eq 'desc'">up<else>down</if>">排序</a>

Related Posts:

评论已关闭。