title: PHP MYSQL data count retrieve from mysql gone wrong
body: <p>I'm new to php and MySQL.  I have a table which I build with this SQL</p>
  
  <pre><code>CREATE TABLE classs
  (sid INT(11) NOT NULL,
  cid INT(11) NOT NULL,
  lid INT(11) NOT NULL,
   date DATE NOT NULL,
  UNIQUE (sid, cid,lid,date));
  </code></pre>
  
  <p>My database input is </p>
  
  <pre><code>sid || cid|| lid date (ALL DATE IS DIFFERENT with in case of same ID)
  ==================================
  2001      ||  1001   || 8
  2001      ||  1001   || 8
  2002      ||  1001   || 8
  2003      ||  1001   || 8 
  2003      ||  1001   || 8
  ==================================
  </code></pre>
  
  <p>Here, I need to build a code using php to display the result like this</p>
  
  <pre><code>2001          2
  2002          1
  2003          2
  </code></pre>
  
  <p>i use this code on my view.php</p>
  
  <pre><code>&lt;?php
  require_once('core/init.php');
  
  $con=mysqli_connect("localhost","root","root","studentattendancesystem");
  
  if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $sql="select *,count(sid) from classs group by sid";
  $result = $con-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0)
  {
    while($row = $result-&gt;fetch_assoc()) 
    {
      $rowcount=mysqli_num_rows($result);
      $sid = $row["sid"];
      echo $sid, " ", $rowcount," ","&lt;br&gt;";    
    } 
  }
  else
  {
    echo 'Failed';
  } 
  </code></pre>
  
  <p>but my output is </p>
  
  <pre><code>2001         3 //should be 2
  2002         3 //should be 1
  2003         3 //should be 2
  </code></pre>
  
  <p>What am I missing?</p>