title: how to create matrix in PHP with data from mysql (2)?
body: <p>I have this code:    </p>
  
  <pre><code>function    random()  
  {  
   include('config/koneksi.php');  
    $result = mysql_query("select * from temp_hasil");  
    $n =mysql_num_rows(mysql_query("SELECT * FROM temp_hasil"));
  
  for ($i = 1; $i &lt;= $n; $i++)
  {
  
   for ($j = 1; $j &lt;= $n; $j++)    
      {
  
             $rows = mysql_fetch_array($result);
  
  
          $this-&gt;table[$i][$j] = $i == $j ? INF :  $rows['id'];
  
  
      }
  }
  }
  
  function    __toString()  
  {  
      $str = '&lt;table class="table table-bordered" id="tableInput"&gt; &lt;tbody&gt;';  
  $str .= '&lt;tr&gt;&lt;td&gt;&lt;/td&gt;';  
  foreach ($this-&gt;table as $rowName =&gt; $row)  
  {  
      $str .= "&lt;td&gt;$rowName&lt;/td&gt;";  
  }  
  $str .= '&lt;/tr&gt;';  
  foreach ($this-&gt;table as $rowName =&gt; $row)  
  {  
      $str .= "&lt;tr&gt;&lt;td&gt;$rowName&lt;/td&gt;";  
      foreach ($row as $columnName =&gt; $value)  
      {  
          $str .= "&lt;td&gt;";  
          $str .=  
              '&lt;input class="form-control" type="text" value="' . $value . '" name="table[' . $rowName . '][' .
              $columnName . ']" requied' . ($columnName == $rowName ? ' disabled' : '') . '&gt;';
          $str .= "&lt;/td&gt;";
      }
      $str .= '&lt;/tr&gt;';
  }
  $str .= '&lt;/tbody&gt;&lt;/table&gt;';
  return $str;
  }
  
  }
  $str .= '&lt;/tr&gt;';  
  foreach ($this-&gt;table as $rowName =&gt; $row)  
  {  
      $str .= "&lt;tr&gt;&lt;td&gt;$rowName&lt;/td&gt;";  
      foreach ($row as $columnName =&gt; $value)  
      {    
          $str .= "&lt;td&gt;";  
          $str .=  
              '&lt;input class="form-control" type="text" value="' . $value . '" name="table[' . $rowName . '][' .
              $columnName . ']" requied' . ($columnName == $rowName ? ' disabled' : '') . '&gt;';
          $str .= "&lt;/td&gt;";    
      }      
      $str .= '&lt;/tr&gt;';    
  }  
  $str .= '&lt;/tbody&gt;&lt;/table&gt;';    
  return $str;    
  }`  
  </code></pre>
  
  <p>and I have table "temp_hasil" such as:        </p>
  
  <pre>
    id_temp  | id |          
    1        |  8 |  
    2        |  5 |    
    3        |  7 |  
  </pre>
  
  <p>If I run this code, it result :   </p>
  
  <pre>
        1     2    3 
   1  | INF  |  5 |  7 |
   2  |      | INF|    |
   3  |      |    | INF|   
  </pre>  
  
  <p>But I want end result such as:  </p>
  
  <pre>
        1     2    3 
   1  | INF  |  5 |  7 |
   2  |  8   | INF|  7 |
   3  |  8   |  5 | INF|   
  </pre>  
  
  <p>How do I code it in php? Is there anything wrong code? Thanks,... :)</p>