【发布时间】:2017-08-25 12:04:14
【问题描述】:
您好,我有这样的网址...
www.example.com/list.php?type=vehicles&stype=Cars
www.example.com/list.php?type=vehicles&stype=Cars&loc=Ludhiana
现在我想根据价格、型号和访问次数对所有结果进行排序。所以我用
$sort="id";
if(isset($_GET['sort'])){
if($_GET['sort']=='P-ASC'){ $sort = "price ASC"; }
elseif($_GET['sort']=='P-DESC'){ $sort = "price DESC"; }
elseif($_GET['sort']=='R-ASC'){ $sort = "model ASC"; }
elseif($_GET['sort']=='R-DESC'){ $sort = "model DESC"; }
elseif($_GET['sort']=='V-ASC'){ $sort = "visits ASC"; }
elseif($_GET['sort']=='V-DESC'){ $sort = "visits DESC"; }
}
现在我想在 url 的末尾添加排序变量来对结果进行排序。例如
www.example.com/list.php?type=vehicles&stype=Cars&sort='**ANYVALUE**'
www.example.com/list.php?type=vehicles&stype=Cars&loc=Ludhiana&sort='**ANYVALUE**'
到目前为止,我正在使用的 href 对我来说绝对没问题...
<a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&sort='**Anyvalue**'"
当我尝试操纵排序值时存在问题,例如我有两个href
<a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&sort='P-ASC'"
<a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&sort='P-DESC'"
当我转到第一个 url 时,它工作正常,当我在使用第一个 url 后转到第二个 url 时,URL 在 URL 中添加另一个排序变量导致 URL 中的两个排序变量。我想要的是
- 检查这些 GET 变量是否存在?
- 如果存在,那么操纵这些变量的值?
- 如果不存在,则将新的 get 变量添加到 URL。
【问题讨论】: