How to use mysql_field_name or mysqli_fetch_field to display Column Name And Value Side By Side
===

I have to write an application that displays a multicolumn value table in two columns(I posted a question concerning that earlier,but i have done some research which has sharpened my perspective). Each individual has a single entry in the table.The task is to display the values in these columns in a two column table.

The columns are for subjects that the individual has registered for.
ie.
         

           MATH111,MATH112,ENG111,ENG112

Etc.These columns are dynamic in nature,because they are based on column headings in an excel sheet which are being loaded into a database. In light of this, i can not "hardcode" the name of the table in my html 

              <th>MATH111</th><th>MATH112</th>........

I need to grab the column names at run time,display the name of the column "**AND**"the value contained in it. The only fixed value in the table is the reg_no of the student.
All other values are arbitrary(including the number of columns in the table).

The basic structure of the table is:

           

           id int auto_increment primary key,
           reg_no varchar(25),
           arbitrary col1 int,
           arbitrary col2 int,
           arbitrary col3 int,
           arbitrary col4 int,
           arbitrary  colx....
In line with the above if i query arbitrary col1 i will get the score obtained in the course that arbitrary col1 represents.

I need to display them in a web-page in the follwing format:
         
          echo '<table><tr><th>Course</th><th>Score</th></tr>';

My query to get the data from the table is 
      


             $sql="select * from '.$table_name.' where reg_no='.$reg_no.';
        ...................................(blah...)
 The good part is that i know the number of columns in the table.(As this figure is saved during table creation). A little research i did yielded the finding that i could use the 'mysql_field_name' function. Or the mysqli_fetch_field function.

   The mysql_field_name will be used in this way(which in my opinion is easier):



            $result=mysql_query($sql, $link); 
            $row=mysql_fetch_array($result); 
   
From here on...i will need some tips:

I want to display "**BOTH**" The field name and the value of the field. So this is how i intend to do it.Please correct me if i am wrong.
 
$numberofcolumnsintable=$numberofcolumnsintable++;
  
     while(int i=1;i<=$numberofcolumnsintable;$i++)
            (I am starting from the index 1(second column because i do not want to display the reg_no or its data)
         {   echo"<tr><td>".mysql_field_name($result,$i)."</td>"<td>".$result[$i]."</td></tr>";
          }
    echo "</table>";

Am I doing it right. I am more comfortable with mysqli functions...but it uses the mysqli_fetch_field function which returns an object with properties of the column..which i have not yet figured out how to access. Any help on that will also be grateful. So back to my main question. Is the code i showed above sufficient to display the column name and its value side by side?.Thanks

