title: While loop for display data from MySQL
body: <p>I created two tables</p>
  <p><strong>1. Table name: &quot;grades&quot;</strong></p>
  <ul>
  <li>id</li>
  <li>subjecttype</li>
  <li>grade</li>
  </ul>
  <p><strong>2. Table name: &quot;subjects&quot;</strong></p>
  <ul>
  <li>id</li>
  <li>name</li>
  <li>subjecttype</li>
  </ul>
  <p>So in next i created table with while loop:</p>
  <pre><code>$sqltest1 = &quot;SELECT * FROM grades, subjects WHERE grades.subjecttype = subject.subjectstype&quot;;
  &lt;table class=&quot;table table-bordered&quot;&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th class=&quot;col-1&quot;&gt;#&lt;/th&gt;
        &lt;th class=&quot;col-3 text-center&quot;&gt;Subject&lt;/th&gt;
        &lt;th class=&quot;col-6 text-center&quot;&gt;Grade&lt;/th&gt;
        &lt;th class=&quot;col-1 text-center&quot;&gt;Options&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
  &lt;!-- ###################################################################### --&gt;
    &lt;?php
    $result = $conn-&gt;query($sqltest1);
    if ($result-&gt;num_rows &gt; 0) {
   
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
        //$id = $row['id'];
  
        echo &quot;&lt;tr&gt;&quot;;
        echo &quot;&lt;td scope='row'&gt;1&lt;/td&gt;&quot;;
        echo &quot;&lt;td&gt;&quot;. $row['name']; &quot;&lt;/td&gt;&quot;;
        echo &quot;&lt;td&gt;&quot;. $row[&quot;grade&quot;].&quot;&lt;/td&gt;&quot;;
        echo &quot;&lt;td class='text-center'&gt;Option&lt;/td&gt;&quot;;
        echo &quot;&lt;/tr&gt;&quot;;
    }
  
  
  } else {
  echo &quot;&quot;;
  }
  
  ?&gt;
  
  &lt;!-- ###################################################################### --&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  <p>My problem is - i want to display all of grades for specify subjecttype in one  but actually i've got something like this:</p>
  <p><a href="https://i.stack.imgur.com/5xoK0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5xoK0.png" alt="enter image description here" /></a></p>
  <p>and I would like to get something like this (image 2) - what am doing wrong?</p>
  <p><a href="https://i.stack.imgur.com/YKxst.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YKxst.png" alt="enter image description here" /></a></p>