簡體   English   中英

結果小於限制時的mysql查詢

[英]mysql query when results are less than the limit

這樣可以正常工作,但是當它返回少於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());

我不確定這對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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM