我正在製作一個網站,它只顯示一個mysql數據庫中的表格,並且有10個colums,我希望能夠排序。喜歡上下,或者我該怎麼說。我有一個代碼allready你可以看到,但它只有一種方法是可以做出和容易排序2種方式?如果有的話可以有人幫助我嗎?PHP mysql對兩種方式進行排序
我很新的PHP
感謝您的所有答案。
$sql = "SELECT * FROM server1";
if(!isset($_GET['sort'])) {
}
elseif ($_GET['sort'] == 'id')
{
$sql .= " ORDER BY ID";
}
elseif ($_GET['sort'] == 'vsite')
{
$sql .= " ORDER BY vsite";
}
elseif ($_GET['sort'] == 'registrar')
{
$sql .= " ORDER BY registrar";
}
elseif ($_GET['sort'] == 'eier')
{
$sql .= " ORDER BY eier";
}
elseif ($_GET['sort'] == 'ns')
{
$sql .= " ORDER BY ns";
}
elseif ($_GET['sort'] == 'a')
{
$sql .= " ORDER BY a";
}
elseif ($_GET['sort'] == 'mx')
{
$sql .= " ORDER BY mx";
}
elseif ($_GET['sort'] == 'flyttet')
{
$sql .= " ORDER BY flyttet";
}
elseif ($_GET['sort'] == 'slettet')
{
$sql .= " ORDER BY slettet";
}
elseif ($_GET['sort'] == 'delt')
{
$sql .= " ORDER BY delt";
}
elseif ($_GET['sort'] == 'behkd')
{
$sql .= " ORDER BY behkd";
}
elseif ($_GET['sort'] == 'varenr')
{
$sql .= " ORDER BY varenr";
}
elseif ($_GET['sort'] == 'server')
{
$sql .= " ORDER BY server";
}
elseif ($_GET['sort'] == 'sist')
{
$sql .= " ORDER BY sistoppdatert";
}
只需爲「ASC」或「DESC」創建另一個字段。雖然我建議你重新考慮整個事情,並使用JS – sinaza