2013-03-02 5 views
0

URL에 변수를 추가하려고합니다. 예 :URL에 추가 변수 추가

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

및 추가 & 가격 = PriceLow

example.co.uk/searchtestingv2.php?categories=rockandpop & 값 = 또 다른 한가지는 내가 해봤됩니다

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

즉 수동으로 추가 :

나는이 시도했다 PriceLow

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

+0

이러한 MySQL 쿼리는 URL과 어떤 관련이 있습니까? –

+0

URL 변수를 대체하지 않고 기존 URL 변수에 추가하려면 어떻게해야합니까? – tech292

답변

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