PHP 获取 URL 错误

标签 php html mysql checkbox get

我有多个复选框,并且 onClick 我正在将值发送到 URL 并从 PHP 中的 URL 获取值,以便我可以从查询中选择结果。

如果我选择美国和国际市场,则 URL 为“product.php?market=US” 但当我选择瓷砖和平板时,它会显示“product.php?market=US-International&type=tiles&type=slabs” 当我返回并再次选择市场为国际后,它显示“product.php?market=US&type=tiles&type=slabs&market=International”

我如何管理 URL 中的获取值,例如 daraz.pk/women/clothing/kurtas-shalwar-kameez/在左侧过滤器上执行的操作。

复选框结构:

市场:

美国 国际

类型:

瓷砖 板

类别:

奥尼克斯 等等

CODE :

<div class="widgetTitle">
                        <h3 class="garis">Market</h3>
                        <div class="productsline"></div>
                    </div>
                    <nav class="categories">



 <input  name="check_list[]" onclick="window.location.href = '?market=Pakistan'"  type="checkbox" id="checkbox-1" class="regular-checkbox" /><label for="checkbox-1"></label>




 <input  name="check_list[]" onclick="window.location.href = '?International&'" type="checkbox" id="checkbox-2" class="regular-checkbox" /><label for="checkbox-2"></label>

                    International





                    </nav>
                </div>

    <div class="widgetTitle">
                        <h3 class="garis">Type</h3>
                            <div class="productsline"></div>
                    </div>

                    <nav class="categories">



<input  name="check_list[]" onclick="window.location.href = '&type=blocks'"  type="checkbox" id="checkbox-3" class="regular-checkbox" /><label for="checkbox-3"></label>
Blocks




 <input  name="check_list[]" onclick="window.location.href = '<?=$path;?>&type=slabs'"  type="checkbox" id="checkbox-4" class="regular-checkbox" /><label for="checkbox-4"></label>

                    Slabs


 <input  name="check_list[]" onclick="window.location.href = '&type=tiles'"  type="checkbox" id="checkbox-5" class="regular-checkbox" /><label for="checkbox-5"></label>

                    Tiles


 <input  name="check_list[]" onclick="window.location.href = '&type=mosaics'"  type="checkbox" id="checkbox-6" class="regular-checkbox" /><label for="checkbox-6"></label>

                    Mosaics




                    </nav>
                </div>

最佳答案

您是使用 php 还是 javascript 构建 url?

使用 PHP:

$_GET['market'] = 'your new market';

echo http_build_query( $_GET );

编辑后:

onClick="?<?php echo http_build_query( array('market' => 'Pakistan') + $_GET ); ?>"

关于PHP 获取 URL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19949024/

相关文章:

php - 使用正则表达式

php - 使用 Dompdf 的 While 循环输出表

html - div 中输入和标签之间的行为差​​异

php - 一般错误 : 1366 Incorrect integer value with Doctrine 2. 1 和 Zend Form 更新

php - Lumen/Laravel 错误 - ReflectionException : Class App\Http\Controllers\Photos\TestController does not exist

php - 我在 Ubuntu 14.04 中使用 codeigniter 得到 URL not found 问题错误

php - 图像随机损坏(但刷新后加载)并显示 "Resource interpreted as Image but transferred with MIME type text/html"

javascript - HTML标签嵌套问题

mysql - 在 SQL 查询中使用 "AND"和 "OR"

javascript - 我的 Sequelize/Node 设置错误?我做错了什么吗?