2017-10-15 83 views
0
執行顯示錯誤

問題出在下面的查詢SQL查詢時用PHP

$query1 = "SELECT SUM(qyt) FROM vip_allotment_details 
      where allotment_id = (SELECT id from vip_allotment 
            where date_from >= '2017-10-1' AND 
            date_to <= '2017-10-31') "; 

當我穿上DATE_TO值超過二零一七年十月十五日它收到以下錯誤

Warning: mysql_query(): Unable to save result set in /home/saudican/public_html/hotel/pages/r_booking_status.php on line 133 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/saudican/public_html/hotel/pages/r_booking_status.php on line 136 

我想不通的地方是查詢的問題...

+2

也許子查詢返回多行。嘗試'allotment_id IN(...)'而不是 – GurV

+0

@GurwinderSingh非常感謝你的工作..謝謝你。 –

+0

不客氣。 – GurV

回答

0

如果返回一個多行使用IN

SELECT 
    SUM(qyt) 
FROM 
    vip_allotment_details 
WHERE 
    allotment_id IN ( 
         SELECT 
         id 
         FROM 
         vip_allotment 
         WHERE 
         date_from >= '2017-10-1' 
         AND 
         date_to <= '2017-10-31' 
        ) 
+0

感謝的人,如果我想顯示從表vip_allotment在php這樣的字段<?php echo $ row ['date_from']?>我怎麼能從這個先前的查詢 –

+0

使用像這樣的變量:$ date from = $ row ['date_from'];使用next:echo($ date_from); – mscdeveloper