title: Display MySQL Data in HTML Table dynamically using PHP 5+ with custom column headings
body: <p>I am new to PHP. I have around 20 columns in a MySQL table. I want to let users select the columns they want to view, so I have made them clickable via checkboxes and gather the selected columns in an array. Somehow I have managed to build the query. But the problem is that I have custom column headings. For example if my column name in MySQL table is <code>student_name</code> I want to display it as "Student Name" (without the quotes). Along with that I want to display only those columns that were selected by the user.</p>
  
  <p>For example I have this MySQL table: student</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;&lt;td&gt;student_id&lt;/td&gt;&lt;td&gt;student_name&lt;/td&gt;&lt;td&gt;student_roll_no&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;1 &lt;/td&gt;&lt;td&gt;           Mr.Red    &lt;/td&gt;&lt;td&gt;     17&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;2  &lt;/td&gt;&lt;td&gt;          Mr.Green  &lt;/td&gt;&lt;td&gt;     20  &lt;/td&gt;&lt;/tr&gt;    
  &lt;tr&gt;&lt;td&gt;3  &lt;/td&gt;&lt;td&gt;          Mr.Orange  &lt;/td&gt;&lt;td&gt;    21&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;4   &lt;/td&gt;&lt;td&gt;         Mr.Red     &lt;/td&gt;&lt;td&gt;    22&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Then any of the columns <code>student_id</code>, <code>student_name</code>, <code>student_roll_no</code> (one, two or all of them) can be selected by the user with the given checkboxes.</p>
  
  <p>I then build a query like</p>
  
  <pre><code>Select student_id, student_name from student where student_name='Mr.Red';
  </code></pre>
  
  <p>When the query is run I want to display its result like this:</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;&lt;th&gt;Student ID &lt;/th&gt;&lt;th&gt;     Student Name&lt;/th&gt;&lt;tr&gt;
   &lt;tr&gt;&lt;td&gt;   1   &lt;/td&gt;&lt;td&gt;           Mr.Red&lt;/td&gt;&lt;tr&gt;
   &lt;tr&gt;&lt;td&gt;   4     &lt;/td&gt;&lt;td&gt;         Mr.Red&lt;/td&gt;&lt;tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>How can I achieve this?</p>
  
  <p>Note that I want to use the improved MySQL functions. Thanks in advance.</p>