dougu1990 2013-09-26 18:13
浏览 9

从第二个表php分组的帖子

This is litle complicated query for me, but if anyone have idea please post id...

I want to make something like this

SITE 1
post
post
post

SITE 2
post
post
post

here is my query

$result = mysql_query("SELECT content.* FROM content WHERE content.site IN
          (SELECT site_id FROM site_subscription WHERE user_id = ".$_SESSION['userid'].")
          ORDER by content.site DESC");

while($row = mysql_fetch_assoc($result)) {
         $array[] = $row;
}

AND im display post

if(is_array($array)) {  
    foreach($array as $row) {
        include($basepath.'/template/item.php');
    }
} 

This is working and post is sorted by site_id, but need to get site_name from other table, table name site and than GROUP post by site_name like above SITE 1, SITE 2, SITE 3

Something like SELECT * FROM site WHERE id='content.site'

  • 写回答

3条回答 默认 最新

  • douren2831 2013-09-26 18:22
    关注

    "SELECT * FROM content INNER JOIN site ON content.site = site.id

    WHERE site.id IN (

      SELECT site_id FROM site_subscription 
    
              WHERE user_id = ".$_SESSION['userid'].")
    

    ORDER BY site.name"

    评论

报告相同问题?