简体   繁体   English

向URL添加其他变量

[英]Adding additional Variable to URL

I'm trying to add additional variables to the url. 我正在尝试向URL添加其他变量。 Eg: 例如:

example.co.uk/searchtestingv2.php?categories=rockandpop example.co.uk/searchtestingv2.php?categories=rockandpop

and add: &prices=PriceLow 并添加:&prices = PriceLow

example.co.uk/searchtestingv2.php?categories=rockandpop&value=PriceLow example.co.uk/searchtestingv2.php?categories=rockandpop&value=PriceLow

I've tried this: 我已经试过了:

$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';
}

Another thing is I've tried to add it manually ie: 另一件事是我尝试手动添加它,即:

http://www.example.co.uk/searchtestingv2.php?categories=rockandpop&value=PriceLow http://www.example.co.uk/searchtestingv2.php?categories=rockandpop&value=PriceLow

and it doesn't work. 而且不起作用。

Here's my code: 这是我的代码:

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'";   
    } 

and

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM