我想排序我的表中從MySQL生成的列數據。這是我多麼希望我的表是: -在列表中排序數據
<th><a href='view.php?sort=first_name'>First Name</th>
<th><a href='view.php?sort=last_name'>Last Name</th>
這是我的查詢,但我得到一個錯誤
Parse error: syntax error, unexpected 'if' (T_IF) in C
$result = mysql_query("SELECT * FROM users")
if($_GET['sort'] == 'first_name'){
$result .= "ORDER BY first_name";
}
else if ($_GET['sort'] == 'last_name'){
$result .= "ORDER BY last_name";
}
or die(mysql_error());
我知道我的問題是,在查詢,但如何我可以糾正它嗎?
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – h2ooooooo
體面的IDE和一些基本的調試功能會使代碼中的錯誤非常明顯。 – vascowhite