Need to get productdata out of mysql database

后端 未结 1 1538
萌比男神i
萌比男神i 2020-12-29 11:02

I got a question. I will try to describe my situation:

I got a wordpress installation which i installed codeigniter in. This all goes good and i also got access to t

1条回答
  •  情歌与酒
    2020-12-29 11:24

    It sounds like you're trying to get several pieces of data from different rows in the same table, which means you need to do more than one join. Does this get you what you're looking for?

    $sql = "SELECT p.id, p.post_title, p.guid, p.post_type, m.meta_key, m.meta_value, meta_sp.meta_value as sale_price, meta_ap.meta_value as additional_price
            FROM wp_posts p
            INNER JOIN wp_postmeta m
            INNER JOIN wp_postmeta meta_sp ON p.id=meta_sp.post_id 
                AND meta_sp.meta_key='sale_price'
            INNER JOIN wp_postmeta meta_ap ON p.id=meta_ap.post_id 
                AND meta_ap.meta_key='additional_price'
            WHERE p.id=m.post_id
            AND m.meta_key='_rentable' AND m.meta_value='yes'
            ";
    

    0 讨论(0)
提交回复
热议问题