我是一名学生编码员。我想创建一个排序按钮,按下该按钮时,按升序对 MYSQL 查询进行排序。然后再次按下时,它将按降序排序。对,现在,它只是背靠背显示升序表和降序表。
形成此按钮逻辑的最佳方法是什么?
<form name="Email Header" method="post" action="{$_SERVER['PHP_SELF']}">
<button type="submit" name="id_sort" class="button" value="1">ID</button>
<button type="submit" name="from_sort" class="button" value="1">FROM</button>
<button type="submit" name="to_sort" class="button" value="1">TO</button>
<button type="submit" name="subject_sort" class="button" value="1">SUBJECT</button>
<button type="submit" name="date_sort" class="button" value="1">DATE</button>
</form>
// SORT
if( isset( $_POST['id_sort'] ) )
if( $_POST['id_sort'] == 1 )
id_ASC_sort();
$_POST['id_sort'] = 0;
if ($_POST['id_sort'] == 0)
if( isset( $_POST['id_sort'] ) )
if( $_POST['id_sort'] == 1 )
id_DESC_sort();
// query
$sql = "SELECT * FROM messages ORDER BY message_id DESC";
$result = mysql_query( $sql );