内爆多维php数组
我在php的电子商务网站上工作。我创建了如下多维php数组:-内爆多维php数组,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我在php的电子商务网站上工作。我创建了如下多维php数组:- Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [1] => Array ( [0] => 5 [1] => 6 [2]
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
[1] => Array
(
[0] => 5
[1] => 6
[2] => 7
)
select * from tbl_product where id IN(select product_id from tbl_vehicleproductequipments where (equipmentvalue_id = 1 OR equipmentvalue_id = 2 OR equipmentvalue_id = 3 OR equipmentvalue_id = 4) AND (equipmentvalue_id = 5 OR equipmentvalue_id = 6 OR equipmentvalue_id = 7)
我正在研究高级搜索选项。我有两个表,一个是product,另一个是productattributes。我想通过OR运算符内爆零索引数组值,通过OR条件内爆一个索引数组值,然后内爆具有零索引和第一个索引的最终数组,如下所示:-
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
[1] => Array
(
[0] => 5
[1] => 6
[2] => 7
)
select * from tbl_product where id IN(select product_id from tbl_vehicleproductequipments where (equipmentvalue_id = 1 OR equipmentvalue_id = 2 OR equipmentvalue_id = 3 OR equipmentvalue_id = 4) AND (equipmentvalue_id = 5 OR equipmentvalue_id = 6 OR equipmentvalue_id = 7)
我尝试过以下代码:-
$eqpcond = "";
if(!empty($_REQUEST["equipmentarr"])){
foreach($_REQUEST["equipmentarr"] as $y => $equipval){
$eqpcond = "select * from tbl_product where id IN (select product_id from tbl_vehicleproductequipments where ";
foreach($equipval as $s => $vl){
$equipcarr[] = " OR equipmentvalue_id = $vl";
}
}
if(!empty($equipcarr)){
$eqpcond = implode(" AND ",$equipcarr).")";
}
}
我得到了这样的问题,这是不正确的
select * from tbl_product where id IN(select product_id from tbl_vehicleproductequipments where equipmentvalue_id = 1 AND OR equipmentvalue_id = 2 AND OR equipmentvalue_id = 3 AND OR equipmentvalue_id = 4 AND OR equipmentvalue_id = 5 AND OR equipmentvalue_id = 6 AND OR equipmentvalue_id = 7)
请帮助我,因为我被困在这种情况下,我不知道如何做到这一点。任何帮助都将不胜感激
提前感谢试试这个..我认为这将生成所需的查询。如果没有,请发布生成查询并进行必要的更改
$eqpcond = "";
if (!empty($_REQUEST["equipmentarr"])) {
foreach ($_REQUEST["equipmentarr"] as $y => $equipval) {
$equipcstr = "";
$equipcarr = array();
$eqpcond = "select * from tbl_product where id IN (select product_id from tbl_vehicleproductequipments where ";
foreach ($equipval as $s => $vl) {
$equipcstr .= " OR equipmentvalue_id = $vl";
}
$equipcstr = trim($equipcstr, 'OR');
$equipcarr[] = $equipcstr;
}
if (!empty($equipcarr)) {
$eqpcond = implode(" AND ", $equipcarr) . ")";
}
}
注意:我认为您没有有效的查询,其中equipmentvalue\u id
在1,2,3,4和5,6,7中的设备值_id如何可能
请查看:
这是你想要的解决方案,使用一些内爆函数
$arr = array(
array(1, 2, 3, 4),
array(5, 6, 7)
);
使用OR的子查询
在中使用子查询
然后最后使用$sql
不要像这样使用子查询INSELECT…,你可以把它们放在一个数组中,生成一个连接变量,然后使用它。你能写下它的代码吗。我只知道这个方法。这部分没有意义:…设备值\u id=1或设备值\u id=2或设备值\u id=3或设备值\u id=4和设备值\u id=5或设备值\u id=6或设备值\u id=7。equipmentvalue\u id不能同时是这两组值中的一组。对子查询进行不同的查询并获取它们,将它们收集到一个数组中,然后$in=join,$fetch\u arr;一个特定产品有多个设备,因此设备值\u id可以同时是这些值中的一个。感谢您的友好回复,但使用此代码,我可以加入第一个数组索引值,但索引值不为零。以上代码的输出为:-选择*从tbl_产品,其中id插入选择产品id从tbl_车辆产品设备,其中设备值_id=5或设备值_id=6或设备值_id=8Ohh抱歉…我的错误。。只需放置$equipcarr=数组;紧接着如果!清空$_请求[equipmentarr]{并查看发生的情况。非常感谢您的友好回复。我接受您的回复。非常感谢。我真的很感激。谢谢..很高兴能提供帮助
$main_sql = select * from tbl_product where id IN($sql);