2013-03-02 176 views
0

我想添加額外的變量到URL。例如:添加額外的變量到URL

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

,並添加:&價格= PriceLow

example.co.uk/searchtestingv2.php?categories=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&value=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"; 
    } 
+0

你能澄清你的問題? – nine7ySix 2013-03-02 21:46:24

+0

這些MySQL查詢如何與URL相關? – 2013-03-02 21:46:44

+0

如何將其他網址變量添加到現有的變量而不替換它? – tech292 2013-03-02 21:47:58

回答

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

嗯,似乎返回錯誤:解析錯誤:語法錯誤,意外',',期待'&'或T_VARIABLE – tech292 2013-03-02 22:06:29