2014-11-08 76 views
-2

當我將以下內容粘貼到phpmyadmin中時,它會正確返回719條記錄。爲什麼在phpMyAdmin中工作,但不在PHP腳本中?

SET SQL_BIG_SELECTS=1; 
select lc.townshipnumber, lc.sectionlegal, sum(fm.acres) FROM lc join fm on 
lc.parcelnumber = fm.parcelnumber join fp on fm.type=fp.soiltype join fc on 
(fp.soilgroup=fc.soilgroup and fp.soilclass=fc.soilclass) where townshipnumber 
<=20 and sectionlegal<=36 and sectionlegal>=1 and fm.year = '2013' group by 
townshipnumber, sectionlegal"; 

當我將其粘貼到PHP腳本,我用$query = (*the select statement from above*)然後$result = $mysqli->query($query) or die ("Errorr in query: $query. ".mysqli_error());

下一行的PHP腳本顯示找到的記錄,但屏幕只是保留爲空爲此特定的查詢。

$records_found=mysqli_num_rows($result); 
echo $records_found.' Records Found<br /><br />'; 
+0

'SET SQL_BIG_SELECTS = 1',將其設置在您的主要查詢之前,它將工作..PHP不會同時執行這兩個命令。 – hutchbat 2014-11-08 02:56:29

+0

你不能用'query()'一次運行多個查詢。分別執行它們或使用[mysqli_multi_query](http://php.net/manual/en/mysqli.multi-query.php) – 2014-11-08 03:21:14

+0

問題已經演變。我把我的整個php程序減少到2行 echo「show this」; SET SQL_BIG_SELECTS = 1; 我只是得到一個空屏幕,除非我註釋掉第二行,然後屏幕上出現「顯示此」字樣就好了。 我在使用HostMonster。我真的認爲我之前可以使用sql_big_selects,但現在不能工作。我可能會聯繫HostMonster作爲下一步。 – 2014-11-08 03:46:24

回答

0

你有結果作爲一個對象,你還沒有實際做過任何有用的事情呢。你可以把它放到一個數組中並循環來獲得結果。

<?php 
    // Save the query results in an array, which you can then loop through 
    var_dump(mysqli_fetch_array($result)); 
+0

我在代碼中使用$ row = mysqli_fetch_row($ result),然後我進一步處理它。問題在於,它甚至會在顯示找到的記錄數的行之前掛在空白屏幕上。如果只是說「找到719條記錄」,我會沒事的。 – 2014-11-08 03:01:29

相關問題