<?php
 include_once 'opendb.php';
 
 $SmanCode=$_POST["SmanCode"];
 $CompID=$_POST["comp_id"];

    if (isset($_POST["SmanCode"]) && isset($_POST["comp_id"]) )
    {
	
        $comp_id   = $_POST["comp_id"];
        $today=date("Ymd");
        $sql = "SELECT count(*) as rcount  FROM sman_reminders WHERE isclosed=0 and comp_id= $comp_id and sman_code='$SmanCode' and rem_date <= ".$today;
        $result = $conn->query($sql);
        $ret=0; 
        if ($result->num_rows > 0 ) {
            if($row = $result->fetch_assoc()) 
            {
                if (is_null($row["rcount"]))
                {                     
                  $ret=0;                      
                }
                else
                {
                    $ret=$row["rcount"];
                }   
            }
        }
        echo $ret;
    }
    else
    {
        echo "ERROR: No input:";
    }
    
    $conn->close();
?>