56,677
社区成员
发帖
与我相关
我的任务
分享
$sql1 = "SELECT username,test FROM bbs.bbs_users where test = 1";
$clubs = $wpdb->get_results($sql1);
foreach($clubs as $club){
$name = $club->user_name;
$sql = "select * from (SELECT a.*,b.user_login,b.ID as user_id FROM cms_posts a LEFT OUTER JOIN cms_users b ON a.post_author = b.ID WHERE b.user_login = '$name' and post_status IN ('publish','static') group by ID order by post_date_gmt DESC limit 1 ) as total group by user_id order by post_date_gmt limit 10";
$POSTS = $wpdb->get_results($sql);
foreach ( $POSTS as $post ) {
$uid2 = $post->user_id;
$username = get_userdata($uid2);
$output = "用户名:".$username->user_login."<br>文章名称:".get_permalink($post->ID).";
}
echo $output;
}
SELECT cp1.*,cu.*,bu.*
FROM mytest.`cms_posts` cp1
LEFT JOIN mytest.`cms_posts` cp2 ON cp1.post_author=cp2.post_author
AND cp1.post_date_gmt<cp2.post_date_gmt
RIGHT JOIN mytest.`cms_users` cu ON cp1.post_author=cu.ID
RIGHT JOIN test.`bbs_users` bu ON cu.user_login=bu.username
GROUP BY cp1.ID
HAVING COUNT(cp2.ID)<1