从值为SQL中的数组的列中获取两个日期

时间:2016-10-15 21:01:09

标签: php mysql sql arrays

我尝试将两个日期日期保存在复杂数组中保存的列表中。我需要这个2日期与"今天"并且只有在这两个日期之间返回id。

这是带有var_dump的数组:

array(1) { 
    ["set_57c440778b89f"]=> array(8) { 
        ["conditions_type"]=> string(3) "all" 
        ["conditions"]=> array(1) { 
            [1]=> array(2) { 
                ["type"]=> string(8) "apply_to" 
                ["args"]=> array(1) { 
                    ["applies_to"]=> string(8) "everyone" 
                }
             } 
        } 
        ["collector"]=> array(1) { 
            ["type"]=> string(7) "product" 
        } 
        ["mode"]=> string(5) "block" 
        ["date_from"]=> string(10) "2016-08-28"     
        ["date_to"]=> string(10) "2016-08-31" 
        ["rules"]=> array(1) { 
            [1]=> array(4) { 
                ["from"]=> string(0) "" 
                ["to"]=> string(0) "" 
                ["type"]=> string(14) "price_discount" 
                ["amount"]=> string(0) "" 
            }
        } 
        ["blockrules"]=> array(1) { 
            [1]=> array(5) { 
                ["from"]=> string(1) "2" 
                ["adjust"]=> string(1) "1" 
                ["type"]=> string(18) "percent_adjustment" 
                ["amount"]=> string(3) "100" 
                ["repeating"]=> string(3) "yes" 
            } 
        } 
    } 
}

这就是我在专栏中看到的内容:

a:1:{s:17:"set_57de848bdde1b";a:8 {s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:1:{s:10:"applies_to";s:8:"everyone";}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:9:"date_from";s:10:"2016-09-01";s:7:"date_to";s:10:"2016-09-30";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:1:"1";s:2:"to";s:1:"1";s:4:"type";s:19:"percentage_discount";s:6:"amount";s:3:"100";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"1";s:6:"adjust";s:1:"1";s:4:"type";s:18:"percent_adjustment";s:6:"amount";s:3:"100";s:9:"repeating";s:3:"yes";}}}}

在我查询的那一刻,我只检索具有此数组属性的id而不过滤范围:

SELECT wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE wp_posts.post_type = 'product'
AND wp_posts.post_status = 'publish'
AND wp_postmeta.meta_key IN ('_pricing_rules')

现在我需要添加类似(伪代码)的东西:

AND wp_postmeta.meta_value.from >= TODAY
AND wp_postmeta.meta_value.from <= TODAY

0 个答案:

没有答案