从nextgen的多个图库ID获取结果

时间:2012-11-22 15:22:41

标签: mysql sql wordpress nextgen-gallery

我认为这更像是与SQL相关的问题而不是与WP相关的问题:::

$result = $wpdb->get_results( " SELECT *
from wp_ngg_gallery, wp_ngg_pictures
where wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
and wp_ngg_gallery.gid = 10
order by wp_ngg_pictures.imagedate 
DESC " );

如果我只是从Gallery ID = 10获取单个图库ID的数据(例如,例如10),则上面的查询工作正常:::我想从多个图库ID中检索数据我怎么能实现这一目标(例如10,8,4):::

1 个答案:

答案 0 :(得分:1)

使用IN

wp_ngg_gallery.gid IN (10,8,4 )

使用ANSI SQL-92语法

的完整查询
SELECT  *
FROM    wp_ngg_gallery
        INNER JOIN wp_ngg_pictures
            ON wp_ngg_pictures.galleryid = wp_ngg_gallery.gid
WHERE   wp_ngg_gallery.gid IN (10,8,4)
ORDER BY wp_ngg_pictures.imagedate DESC