首页 > 解决方案 > 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);
    }

     ?>

标签: phpapipostmysqli

解决方案


 <?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);
}

 ?>

推荐阅读