我正在使用数组值创建过滤器查询。它可以工作。但是如果数组值为null,则它不起作用。如果我从头开始创建,它甚至可以为null。我想动态创建它。
这是我的代码
$city_array=array('yangon','mandalay','myeik');
$data_city=implode("','",$city_array);
$brand_array=array('huawei','samsung','sony');
$data_brand=implode("','",$brand_array);
$camera_array=array('rear camera');
$data_camera=implode("','",$camera_array);
$operator_array=array('mpt');
$data_operator=implode("','",$operator_array);
$size_array=array('');
$data_size=implode("','",$size_array);
$ram_array=array('');
$data_ram=implode("','",$ram_array);
$memory_array=array('');
$data_memory=implode("','",$memory_array);
$feature_array=array('');
$data_feature=implode("','",$feature_array);
$query = mysql_query ("
select cp.product_id,
temp_operator.nid, temp_operator.operator1, temp_operator.operator2, temp_operator.operator3, temp_operator.operator4,
temp_camera.camera1,temp_camera.camera2,
temp_feature.feature1,temp_feature.feature2,temp_feature.feature3,temp_feature.feature4,temp_feature.feature5,
n.title as model,
f_manage.filename as image,
fprice.commerce_price_amount AS price,
ttdcondition.name as `condition`,
ttd.name as manufacture,
ttdcity.name as city,
ttdsize.name as display_size,
ttdram.name as ram,
ttdmemory.name as memory
FROM temp_table_1 as temp_operator
INNER JOIN node as n
INNER JOIN field_data_field_product as fdfp
INNER JOIN commerce_product as cp
INNER JOIN temp_table_2 as temp_camera
INNER JOIN temp_table_3 as temp_feature
INNER JOIN
field_data_field_product_image as f_product_image
INNER JOIN
file_managed as f_manage
INNER JOIN
field_data_commerce_price as fprice
INNER JOIN
field_data_field_ph_condition as fcondition
INNER JOIN
taxonomy_term_data as ttdcondition
INNER JOIN
field_data_field_brand as fbrand
INNER JOIN
taxonomy_term_data as ttd
INNER JOIN
field_data_field_city as fcity
INNER JOIN
taxonomy_term_data as ttdcity
INNER JOIN
field_data_field_ph_display_size as fsize
INNER JOIN
taxonomy_term_data as ttdsize
INNER JOIN
field_data_field_ram as fram
INNER JOIN
taxonomy_term_data as ttdram
INNER JOIN
field_data_field_ph_internal_memory as fmemory
INNER JOIN
taxonomy_term_data as ttdmemory
ON temp_operator.nid = n.nid
AND temp_camera.nid = n.nid
AND temp_feature.nid = n.nid
AND fdfp.entity_id=n.nid
AND fdfp.field_product_product_id =cp.product_id
AND f_product_image.entity_id = cp.product_id
AND f_product_image.field_product_image_fid = f_manage.fid
AND fprice.entity_id=cp.product_id
AND fcondition.field_ph_condition_tid=ttdcondition.tid
AND n.nid=fcondition.entity_id
AND fbrand.field_brand_tid=ttd.tid
AND fbrand.entity_id=n.nid
AND fcity.field_city_tid=ttdcity.tid
AND n.nid=fcity.entity_id
AND ttdsize.tid=fsize.field_ph_display_size_tid
AND n.nid=fsize.entity_id
AND ttdram.tid=fram.field_ram_tid
AND n.nid=fram.entity_id
AND ttdmemory.tid=fmemory.field_ph_internal_memory_tid
AND n.nid=fmemory.entity_id
where ttd.name in ('$data_brand')
and ttdcity.name in ('$data_city')
and ttdcondition.name in ('$data_condition')
and ttdmemory.name in ('$data_memory')
and ttdram.name in ('$data_ram')
and (temp_camera.camera1 in ('$data_camera') or temp_camera.camera2 in ('$data_camera'))
and ttdsize.name in ('$data_size')
and (temp_operator.operator1 in ('$data_operator') or temp_operator.operator2 in ('$data_operator')
or temp_operator.operator3 in ('$data_operator') or temp_operator.operator4 in ('$data_operator'))
and (temp_feature.feature1 in ('$data_feature') or temp_feature.feature2 in ('$data_feature')
or temp_feature.feature3 in ('$data_feature') or temp_feature.feature4 in ('$data_feature')
or temp_feature.feature5 in ('$data_feature') )
") or die(mysql_error());
while($row = mysql_fetch_assoc($query)) {
$row_array[]=$row;
}
?>