2014-07-25 29 views
-1

快速的問題 - 這是字面上拉我的頭髮(剩下的是什麼)。得到一個mysql查詢的記錄數

這裏是SQL查詢:

 $getRecords = "SELECT * FROM events"; 
     $findRecords = mysql_query($getRecords, $dbhandle); 
     $count = mysql_num_rows($findResults); 
     echo "<p>Showing $count Event(s)</p>"; 

我得到這個返回

警告:mysql_num_rows()預計參數1是資源,空給出

我以後其他的SQL查詢這和他們都工作得很好 - 即使在以前的網站我已經使用這個公式,它一直工作,但在這個項目上敲我回

Th anks提前,你可以在這個

埃裏克

+1

嘗試使用'$ dbhandle',而不是'$ findResults'爲'mysql_num_rows' – Gavin

+1

'mysql_num_rows'使用結果集,而不是數據庫句柄。 – andrewsi

+0

如果您的查詢結果非常大,您可能需要查詢查詢本身的結果大小:'select count(*)as num_rows from events'。一旦執行查詢,您可以計算出您的分頁內容,然後發出數據查詢。 – pp19dd

回答

0

變化

$count = mysql_num_rows($findResults); 

閃耀任何光

$count = mysql_num_rows($findRecords); 
+0

我是個白癡! - 盯着我的臉 – ericH

0

$ findResult沒有設置,所以它是空的。

$getRecords = "SELECT * FROM events"; 
$findRecords = mysql_query($getRecords, $dbhandle); 
$count = mysql_num_rows($findRecords); 
echo "<p>Showing $count Event(s)</p>"; 

另外,您不應該使用mysql_ *函數,因爲它們已被棄用。切換到mysqli或pdo同樣簡單。

+0

謝謝,謝謝,謝謝,謝謝,我是個白癡! – ericH

0

如果mysql_num_rows($findResults)回報false,那是因爲你的要求已經錯...

通過mysql_num_rows($findRecords)變化mysql_num_rows($findResults) ...

+0

非常感謝你的回覆 – ericH