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. mysql_num_rows返回TRUE
- 3. php json_decode每次都返回null
- 4. Drupal - db_fetch_array每行返回NULL
- 5. 又一次findFragmentByTag()返回null
- 6. 每次返回false
- 7. mysql_num_rows始终返回1
- 8. 为什么mysql_num_rows返回零?
- 9. mysql_num_rows总是返回0
- 10. Google Maps API - GDirections.getDuration()第一次返回null,第二次返回
- 11. wglCreateContext()每次在OpenGL和Visual C++中返回NULL
- 12. GoogleSignInResult#isSuccess()每次返回false
- 13. BMI Calculator每次返回0
- 14. null == null返回false?
- 15. getElementById成功一次,然后返回null
- 16. 返回null或抛出异常一次
- 17. PropertyInfo.GetValue(null,null)返回null
- 18. 空白表返回mysql_num_rows($结果)= 1
- 19. mysql_num_rows()函数返回的对象
- 20. 即使mysql_fetch_array返回结果mysql_num_rows返回零
- 21. UISwitch返回NULL?
- 22. getElementById返回null
- 23. ListView.getTag()返回null
- 24. LocationManager返回null
- 25. BitmapFactory.decodeFile()返回null
- 26. FindFragmentByTag返回null。
- 27. GetEditMenu()返回NULL
- 28. mysql_fetch_assoc返回NULL
- 29. cvCapturefromCAM()返回NULL
- 30. Android:TelephonyManager.getSimSerialNumber()返回null
避免使用'mysql_ *'扩展名。为此,“mysql_query”在哪里? – Thamilan
首先比'mysql_num_rows'做'query'。 –
是否使用'mysql_query()' –