-2

I have an multiple category on my page to filter search.

http://localhost/shop/category/produkunggulan/CT0002

Example I have this category:

Brand

$qBrandList = mysqli_query($con, "SELECT P.productid, P.brandid_fk, B.Brandid, B.brand_name FROM tb_product P, tb_brand B WHERE P.brandid_fk = B.brandid AND P.categoryid_fk LIKE '%" . $getCategoryID . "%' GROUP BY B.brandid ORDER BY B.brand_name ASC");
while($dBrandList = mysqli_fetch_array($qBrandList))
{
?>
    <div><label><input name="chkBrand[]" class="chkBrand" type="checkbox" value="<?php echo $dBrandList['brandid_fk']; ?>"/> <?php echo $dBrandList['brand_name']; ?></label></div>
<?php
}

Discount

<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

Now I want when user click the checkbox, it will be directly redirect to the url including the key of category (every click checkbox) and remove the value if uncheck.

Example I click EMORI then FOSSIL, so the URL should be:

http://localhost/shop/category/produkunggulan/CT0002?brand=BR0003,BR0010

enter image description here

halfer
  • 18,701
  • 13
  • 79
  • 158
HiDayurie Dave
  • 1,586
  • 1
  • 14
  • 31

1 Answers1

1
<label><input type="checkbox" name="discount" value="Y"/> Diskon</label>

I don't think you need to use a checkbox to redirect. Simply use input type 'submit'.

<label><input type="submit" name="discount" value="Diskon"/> 

or add onchange event to submit

<label><input type="checkbox" onChange="this.form.submit()" name="discount" value="Y"/> Diskon</label>

also use 'get' method in the tag to show your data at url.

One thing for sure your url wont look as you mentioned rather that it will look as

http://localhost/shop/category/produkunggulan/CT0002?chkBrand%5B%5D=BR0003& chkBrand%5B%5D=BR0010

Here %5B is for'[' and %5D is for ']'.

Yasin
  • 126
  • 2
  • 11