2012-09-12 22 views
3

這工作正常,但返回的結果少於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()); 

回答

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 
+0

的偉大工程,非常感謝 – than107

+0

@ than107沒有什麼問題,歡迎SO並請轉發支付它。 – invertedSpear

+0

謝謝,會做! – than107