我试图添加额外的变量到url。如:
example.co.uk/searchtestingv2.php吗?类别= rockandpop
and add: &prices=PriceLow
example.co.uk/searchtestingv2.php ?类别= rockandpop&价值= PriceLow
我试过了:
$query = parse_url($url, PHP_URL_QUERY);
// Returns a string if the URL has parameters or NULL if not
if( $query ) {
$url .= '&categories';
}
else {
$url .= '?categories';
}
另一件事是我试图手动添加它,例如:
http://www.example.co.uk/searchtestingv2.php?categories=rockandpop&价值= PriceLow
不工作
下面是我的代码:
if($_GET['categories'] == 'rockandpop') {
$query = "SELECT * FROM searchacts WHERE category='Rock and Pop'";
}
if($_GET['categories'] == 'tributebands') {
$query = "SELECT * FROM searchacts WHERE category='Tribute Bands'";
}
和
if(isset($_GET['value'])) {
if($_GET['value'] == 'PriceLow') {
$query = "SELECT * FROM searchacts ORDER BY price ASC";
}
elseif($_GET['value'] == 'PriceHigh') {
$query = "SELECT * FROM searchacts ORDER BY price DESC";
}
elseif($_GET['value'] == 'NameAZ') {
$query = "SELECT * FROM searchacts ORDER BY name ASC";
}
elseif($_GET['value'] == 'NameZA') {
$query = "SELECT * FROM searchacts ORDER BY name DESC";
}
else {
$query = "SELECT * FROM searchacts";
}
function UpdateUrlParam(name, value)
{
var href = window.location.href;
var regex = new RegExp("[&\?]" + name + "=");
if(regex.test(href))
{
regex = new RegExp("([&\?])" + name + "=\d+");
window.location.href = href.replace(regex, "$1" + name + "=" + value);
}
else
{
if(href.indexOf("?") > -1)
window.location.href = href + "&" + name + "=" + value;
else
window.location.href = href + "?" + name + "=" + value;
}
}
UpdateUrlParam('value', 'priceLow);