Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取行数_Php_Mysql - Fatal编程技术网

Php 获取行数

Php 获取行数,php,mysql,Php,Mysql,我需要得到studentID的行数,如果计数超过10,则返回 这就是我到目前为止写的。但似乎不起作用 $findID = ID1231275; $gipct = mysql_query("SELECT COUNT(studentID) FROM classFees WHERE studentID = '".$findID."'"); if ($gipct>10) { echo ("$gipct"); } 顺便说一句,mysql_uu函数已被弃用,并且可以/将在未来的php版本中删除,我建

我需要得到studentID的行数,如果计数超过10,则返回

这就是我到目前为止写的。但似乎不起作用

$findID = ID1231275;
$gipct = mysql_query("SELECT COUNT(studentID) FROM classFees WHERE studentID = '".$findID."'");
if ($gipct>10) {
echo ("$gipct");
}

顺便说一句,mysql_uu函数已被弃用,并且可以/将在未来的php版本中删除,我建议您查看PDO语句或mysqli_uuu函数

如果您使用的是php>5,那么您必须使用mysqli而不是mysql类。然后试试这个:

$db = new mysqli('localhost','user','pass','database');
$searchID = 'ID1231275';
$stmt = $db->prepare("SELECT COUNT(studentID) FROM classFees WHERE studentID =? ");
$stmt->bind_param('s', $searchID);
$stmt->execute();
$stmt->bind_result($gipct);
$stmt->fetch();
if ($gipct > 10) {
 echo ($gipct);
}

$gipct
是一个mysql资源。因此,您必须使用函数
mysql\u num\u rows
来获取所有选中的行

这在您的情况下不起作用,因为您的查询中有一个计数,所以您只得到一行

在您的情况下,您必须首先获取数据

$gipct = mysql_query("SELECT COUNT(studentID) AS countout FROM classFees WHERE....");

$row = mysql_fetch_object($gpict);
if ($row->countout > 10) {
   echo ("$gipct");
}
或者使用
mysql\u num\u rows

$gipct = mysql_query("SELECT * FROM classFees WHERE student...");

if (mysql_num_rows($row) > 10) {
   echo ("$gipct");
}

但是在这里,您可以选择比第一个解决方案慢得多的所有记录。

ID1231275
应该是字符串,而不是常量。mysqli_query()中的数据库连接在哪里?您在查询中使用了过程样式,因此需要提供数据库连接
$gipct = mysql_query("SELECT * FROM classFees WHERE student...");

if (mysql_num_rows($row) > 10) {
   echo ("$gipct");
}