3

这很好用,但是当它返回少于 8 个结果时会出现问题。除了对缺少的其余结果重复查询之外,还有其他选择吗?任何帮助将不胜感激,谢谢。

       $vacation = mysql_query("SELECT i.* 
       FROM vacation_offer_tbl i
       INNER JOIN vacation_offer_pics_tbl c ON (c.vacat_offer_id = i.vacat_offer_id)
       WHERE i.conditional ='1' 
       AND c.pic_1 != ''
       // if < 8 results rerurn the rest where c.pic_1 ='nothing' 
       ORDER BY rand() 
       LIMIT 8") or die(mysql_error());
4

1 回答 1

1

我不确定这将如何工作,ORDER BY rand()但这样的事情可能会有所帮助

SELECT i.*, if(c.pic_1 != '',0,1) as sortOn
FROM vacation_offer_tbl i
INNER JOIN vacation_offer_pics_tbl c ON (c.vacat_offer_id = i.vacat_offer_id)
WHERE i.conditional ='1' 
ORDER BY sortOn, rand() 
LIMIT 8
于 2012-09-12T22:31:22.830 回答