-1
행 세트의 순서를 오름차순에서 내림차순으로 또는 그 반대로 동적으로 변경할 수 있기를 원합니다.링크에서 동적으로 오름차순으로 명령을 설정할 수 있습니까
<a href="file.php?sort=">
과 비슷하지만 클릭 정렬 후 "asc"를 클릭하면 sort = "desc"가 발생하므로 $_GET
으로 가져올 수 있으며이를 mysql 쿼리에 사용하기 위해 변수에 넣을 수 있습니다.
이 내 코드
if(isset($_SESSION['is_logged']) === true)
{
$url_array = array("date_added", "username", "title", "content");
$order = "date_added";
if (isset($_GET['order_by']) && in_array($order, $url_array))
{
$order = $_GET['order_by'];
}
echo '<table border="1" cellpadding="5" cellspacing="2">';
echo '<tr>Sort: ▼ <br />'
. '<th><a href="?order_by=date_added&type=">somestuff</a></th>'
. '<th><a href="?order_by=username">somestuff</a></th>'
. '<th><a href="?order_by=title">somestuff</a></th>'
. '<th><a href="?order_by=content">somestuff</a></th>'
. '</tr>';
$query = run_q('SELECT * FROM posts as p, users as u WHERE p.added_by=u.user_id ORDER BY '.$order.' DESC');