title: HTML table with sql data in php (table row depend by sql columns)
body: <p>Hello i got this sample data in sql </p>
  
  <pre><code>$data = array(
    array('id' =&gt; '1','name' =&gt; 'name1','surname' =&gt; 'surname1'),
    array('id' =&gt; '2','name' =&gt; 'name2','surname' =&gt; 'surname2'),
    array('id' =&gt; '3','name' =&gt; 'name3','surname' =&gt; 'surname3'),
    array('id' =&gt; '4','name' =&gt; 'name4','surname' =&gt; 'surname4')
  );
  </code></pre>
  
  <p>I want to dispplay in in html table but my code didnt work :</p>
  
  <pre><code>&lt;?php
  mysql_connect("localhost", "root", "");
  mysql_select_db("test");
  $select_data = "SELECT * FROM dane ORDER BY `id` DESC";
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html"&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table style="width: 100%;" border="1" cellspacing="5" cellpadding="5"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th align="left" valign="middle"&gt;id&lt;/th&gt;
                      &lt;th align="center" valign="middle"&gt;name&lt;/th&gt;
                      &lt;th align="center" valign="middle"&gt;surname&lt;/th&gt;                    
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;?php
              $result = mysql_query($select_data);
              while ($data = mysql_fetch_row($result)) { 
              }
              ?&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td align="center" valign="middle"&gt;&lt;?php echo $data['id']; ?&gt;&lt;/td&gt;
                      &lt;td align="center" valign="middle"&gt;&lt;?php echo $data['name']; ?&gt;&lt;/td&gt;
                      &lt;td align="left" valign="middle"&gt;&lt;?php echo $data['surname']; ?&gt;&lt;/td&gt;
                  &lt;/tr&gt;    
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But i wann't also that the numer of rows in html table depends by number of columns in sql table. For example in this case i want to display only three rows (three columns in sql table). When i add the column's to sql table i want to rows in html output table  increses dynamicly.</p>
  
  <p>Could someone help me with this code ?</p>