当结果小于限制时mysql查询
问题描述:
这工作正常,但返回的结果少于8个时出现问题。 有没有其他方法可以重复查询剩余的结果? 任何帮助,将不胜感激,谢谢。当结果小于限制时mysql查询
$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());
答
林不知道有多好,这将与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
的伟大工程,非常感谢 – than107
@ than107没有什么问题,欢迎SO并请转发支付它。 – invertedSpear
谢谢,会做! – than107