title: Counting table rows in PHP
body: <p>I am working on a project and I need to find a way to count the table rows when a user has selected a Group from the drop-down box. I have tried some ways in which I can show, but also I am not grasping how this concept would work. I am also using an SQL database which works perfectly, the rows is giving me a hard time though.</p>
  <pre><code>
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;form action=&quot;Web4.php&quot; method=&quot;post&quot;&gt;
      &lt;label form=&quot;return&quot;&gt;Group: &lt;/label&gt;
      &lt;select id=&quot;return&quot; name=&quot;return&quot;&gt;
          &lt;option value=&quot;G&quot;&gt;All&lt;/option&gt;
          &lt;option value=&quot;A&quot;&gt;Group A&lt;/option&gt;
          &lt;option value=&quot;B&quot;&gt;Group B&lt;/option&gt;
          &lt;option value=&quot;C&quot;&gt;Group C&lt;/option&gt;
          &lt;option value=&quot;D&quot;&gt;Group D&lt;/option&gt;
          &lt;option value=&quot;E&quot;&gt;Group E&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type=&quot;submit&quot;&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  $servername = &quot;servername&quot;;
  $username = &quot;myusername&quot;;
  $password = &quot;mypassword&quot;;
  $dbname = &quot;mydatabasename&quot;;
  
  $conn = new mysqli($servername, $username, $password, $dbname);
  
  
  if ($conn-&gt;connect_error) {
      die(&quot;Connection Failed: &quot;. $conn-&gt;connect_error);
  }
  
  if(!isset($_POST[&quot;return&quot;])) {$selval =&quot;G&quot;;}
  else {$selval = $_POST[&quot;return&quot;];}
  
  if($selval == &quot;G&quot;){
     $scores = mysqli_query($conn, &quot;select * from test_scores;&quot;);
  }
  elseif($selval == &quot;A&quot;){
      $scores = mysqli_query($conn, &quot;select * from test_scores WHERE group_id='A';&quot;);
  }
  elseif($selval == &quot;B&quot;){
     $scores = mysqli_query($conn, &quot;select * from test_scores WHERE group_id='B';&quot;);
  }
  elseif($selval == &quot;C&quot;){
    $scores = mysqli_query($conn, &quot;select * from test_scores WHERE group_id='C';&quot;);
  }
  elseif($selval == &quot;D&quot;){
    $scores = mysqli_query($conn, &quot;select * from test_scores WHERE group_id='D';&quot;);
  }
  else{
     $scores = mysqli_query($conn, &quot;select * from test_scores WHERE group_id='E';&quot;);
  }
  
  
  ?&gt;
  
  
  &lt;table border=&quot;1&quot;&gt;
  &lt;tr&gt;&lt;th&gt;Record ID&lt;/th&gt;&lt;th&gt;Math Score&lt;/th&gt;&lt;th&gt;Reading Score&lt;/th&gt;&lt;th&gt;Writing Score&lt;/th&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;?php
  
  while($row = mysqli_fetch_array($scores)){
     echo &quot;&lt;tr&gt;&lt;td&gt;&quot;.$row[&quot;group_id&quot;].&quot;&lt;/td&gt;&lt;td&gt;&quot;.$row[&quot;math&quot;].&quot;&lt;/td&gt;&lt;td&gt;&quot;.$row[&quot;reading&quot;].&quot;&lt;/td&gt;&lt;td&gt;&quot;.$row[&quot;writing&quot;].&quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;;
  }
  
  ?&gt;
  
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>