我有很多自定义字段 - 价格、重量等............
现在我正在尝试基于此创建自定义搜索,并且我想按最小值和最大值进行搜索......不知何故我无法创建确切的查询............将感谢某人对此的帮助..
这是我正在尝试的查询
$where = "";
if ( isset( $_POST['pricemin']) && $_POST['pricemin'] != "" ) {
$pricemin = $_POST['pricemin'];
$where .= " and (SELECT post_id from wp_postmeta where meta_key='list_price' and meta_value > ".$pricemin.$order.") ";
}
if ( isset( $_POST['pricemax']) && $_POST['pricemax'] != "" ) {
$pricemax = $_POST['pricemax'];
$where .= " and (SELECT post_id from wp_postmeta where meta_key='list_price' and meta_value < ".$pricemax.$order.") ";
}
这是最后一行..
"SELECT * from wp_posts where ID IN (select 1 from wp_postmeta ".$where.")"
关于 UNION、INTERSECT 等的任何建议或最好的方法............谢谢
其实 mysql Between 解决了我一半的问题......我可以全部写成
if ( isset( $_POST['pricemin'] ) && $_POST['pricemin'] != "" ) {
$pricemin = $_POST['pricemin'];
$wherep1= " (SELECT post_id from wp_postmeta where meta_key='list_price' and meta_value > ".$pricemin.$order.") ";
}
if ( isset( $_POST['pricemax'] ) && $_POST['pricemax'] != "" ) {
$pricemax = $_POST['pricemax'];
$wherep1 = " (SELECT post_id from wp_postmeta where meta_key='list_price' and meta_value < ".$pricemax.$order.") ";
}
if ( isset($_POST['pricemin'] ) && $_POST['pricemin'] != "" && isset( $_POST['pricemax'] ) && $_POST['pricemax'] != "" ) {
$pricemin = $_POST['pricemin'];
$pricemax = $_POST['pricemax'];
$wherep1 = " (SELECT post_id from wp_postmeta where meta_key='list_price' and meta_value BETWEEN ".$pricemin." and ".$pricemax ." ".$order.") ";
}
但是后来我也想搜索体重,身高............
所以,像 Intersect 这样的东西可以帮助我..但我看到 MYSQL 不支持 INTERSECT........所以,问题仍然是如何重写查询
A 相交 B 相交 C 相交 D 在 mysql 中