if (isset($_GET["val"])) {
$val = $_GET["val"];
$sql1 = "select count(*) as count from staff_log l where l.time_in is null and l.time_out is not null and l.date_today = curdate() and l.staff_id = ".$val.";";
$result1 = mysql_num_rows($sql1);
}
回答
加入這一行...
$result = mysql_query($sql1);
$result1 = mysql_num_rows($result);
必須在mysql_query()
功能定義查詢;
使用mysqli_ *做解決方案並添加一些警告消息,以免使用'mysql_ *'.... –
yeap ... mysql_ *現在已被棄用。 – JohnB
mysql_num_rows()
返回,如在PHP manual所示:
行中一個結果集上或FALSE的成功失敗的次數。
這意味着執行它時出錯,這顯然是因爲您沒有運行任何查詢(mysql_query()
)。
注意,PHP手冊也有在頁面的頂部以下警告:
這個擴展被廢棄在PHP 5.5.0,它是PHP 7.0.0中刪除。相反,應該使用MySQLi或PDO_MySQL擴展。
首先執行查詢,然後NUM_ROWS
原來的MySQL擴展現在已經過時,並連接到數據庫時,會產生E_DEPRECATED錯誤。而是使用MYSQLi或PDO_MySQL擴展。
試試這個
if (isset($_GET["val"]))
{
$val = $_GET["val"];
$sql1 = "select count(*) as count from staff_log l where l.time_in is null and l.time_out is not null and l.date_today = curdate() and l.staff_id = ".$val.";";
$result = mysql_query($sql1);
$count = mysql_num_rows($result);
}
你幾乎權利,請查看下面的代碼。您需要使用mysql_query(),mysql_query()用於執行默認數據庫的查詢。
if (isset($_GET["val"]))
{
$val = $_GET["val"];
$sql1 = "select count(*) as count from staff_log l where l.time_in is null and l.time_out is not null and l.date_today = curdate() and l.staff_id ='$val'";
$sql2 = mysql_query($sql1); // Execute the query first
$result1 = mysql_num_rows($sql2); // Get the number of rows from executed query result.
echo "The count is $result1";
}
- 1. MultipartFile每次都返回NULL
- 2. php json_decode每次都返回null
- 3. mysql_num_rows()返回零
- 4. mysql_num_rows返回TRUE
- 5. mysql_num_rows null
- 6. Drupal - db_fetch_array每行返回NULL
- 7. 又一次findFragmentByTag()返回null
- 8. 每次返回false
- 9. mysql_num_rows總是返回0
- 10. mysql_num_rows始終返回1
- 11. mysql_num_rows始終返回1
- 12. 爲什麼mysql_num_rows返回零?
- 13. 爲什麼mysql_num_rows()返回0?
- 14. Google Maps API - GDirections.getDuration()第一次返回null,第二次返回
- 15. 每次調用onCreateContextMenu和返回null的菜單項
- 16. 分段控件:titleForSegmentAtIndex每次都返回null
- 17. wglCreateContext()每次在OpenGL和Visual C++中返回NULL
- 18. 每次都返回TRUE
- 19. BMI Calculator每次返回0
- 20. GoogleSignInResult#isSuccess()每次返回false
- 21. JQuery .is:checked每次返回false
- 22. null == null返回false?
- 23. SQL查詢返回每個值爲NULL
- 24. JOOQ API getPrimaryKey()對每個表返回null?
- 25. 返回null或拋出異常一次
- 26. 設備令牌第一次返回null
- 27. 的BufferedReader返回null第二次使用
- 28. 第二次調用strtok()返回null
- 29. getElementById成功一次,然後返回null
- 30. PropertyInfo.GetValue(null,null)返回null
避免使用'mysql_ *'擴展名。爲此,「mysql_query」在哪裏? – Thamilan
首先比'mysql_num_rows'做'query'。 –
是否使用'mysql_query()' –