默认顺序 table

Order table by default

我目前正在开发一个事件日历,它允许用户在日期和地点以及日期和地点之间进行排序。

这是我用于订单的代码:

$order = isset($_GET['sort'])?$_GET['sort']:'date_added';
$result = mysqli_query($con,"SELECT * FROM calendar ORDER BY $order");
$sql = mysql_query($query);

现在,当您点击一个按钮时,它会像这样设置将用于排序的变量

onclick="location.href=' index.php?sort=date&place'"

现在效果很好,但是当我启动我的活动日历时,它是空白的...我怎样才能为我的日历设置默认顺序?

这是日历输出的代码:

echo "<table class='table table-striped' >
<thead>
<tr>
<th>Artist</th>
<th>Place</th>
<th>Date</th>
<th>Genre</th>
</tr>
</thead>";


while($row = mysqli_fetch_array($result))
{
    $date = $row['date'];
 $convdate = date('d-m-Y', strtotime($row['date']));

echo "<tr>";
echo "<td>" . $row['artist'] . "</td>";
echo "<td>" . $row['place'] . "</td>";
echo "<td>" . $convdate . "</td>";
echo "<td>" . $row['genre'] . "</td>";
echo "</tr>";

}
echo "</table>";

mysqli_close($con);



?>

这样的设置顺序是正确的。但是有 mysql_query 没有意义。把它丢掉。 出于安全原因(SQL 注入)我建议您在查询中使用之前转义字符串。

$order = isset($_GET['sort']) ? $_GET['sort'] : 'date_added';
$order = mysqli_real_escape_string($con, $order);
$result = mysqli_query($con,"SELECT * FROM calendar ORDER BY $order");

字段名是"date&place"?

注意 URL 中的 & 符号应该被转义,否则 $_GET 将把 "place" 作为另一个不同的参数。

how can I give my calendar a default order?

"default order" 是什么意思?

$order = isset($_GET['sort'])?$_GET['sort']:'date_added'; $result = mysqli_query($con,"SELECT * FROM calendar ORDER BY $order"); $sql = mysql_query($query);

永远不要将未经测试的值传递给 sql 语句。

onclick="location.href=' index.php?sort=date&place'"

这不会导致 $_GET['sort']=='date&place',url 中的 & 标记一个新变量。