php - How to get the number of rows in database based on few parameters
问题描述
i have been try to count the number of rows inside a SQL table on the basis of few post method parameter, so, I have been able to connect to the database and wrote the code for the counting too but somehow it is not returning me anything, the postman window is blank, so it means that there is a successful connection but somehow nothing goes beyond that,
<?php
//checking if the script received a post request or not
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting post data
$match_id=$_POST['match_id'];
$rs=$_POST['rs'];
require_once('connect.php');
$sql = "select count(1) From OneRecord where match_id='$match_id' and
rs='$rs'";
if($result=mysqli_query($con,$sql)){
$row = mysql_fetch_array($result);
$total = $row[0];
echo "Total rows: " . $total;
}
else
{
echo 'oops! Please try again!';
}
mysqli_close($con);
}
?>
解决方案
<?php
//checking if the script received a post request or not
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting post data
$match_id=$_POST['match_id'];
$rs=$_POST['rs'];
require_once('connect.php');
$sql = "select * From OneRecord where match_id='$match_id' and rs='$rs'";
if($result=mysqli_query($con,$sql)){
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf(" %d rows.\n",$rowcount);
// Free result
mysqli_free_result($result);
}
else
{
echo 'oops! Please try again!';
}
mysqli_close($con);
}
?>
推荐阅读
- reactjs - Nextjs 项目未编译为 ES5
- flutter - Flutter AnimatedList 和 AnimatedController
- mysql - Mysql连接mariadb容器失败
- excel - 如何复制公式结果
- react-bootstrap - 如何删除 react-bootstrap Carousel 动画并使其仅在点击时移动?
- visual-studio-code - VSCode remote-ssh 无法连接到 win server 2019
- mongodb - Mongo 聚合:如何从数组中排除项目,如果它们没有特定的键?
- typescript - 返回具有传入函数参数值的参数类型的函数对象
- python-3.x - 类型错误:process_session() 缺少 1 个必需的位置参数:“会话”
- spring-boot - 基于关键字的查询的 REST API 设计