title: student's marks report
body: <p>Please help me to write this code 
  i want to display table like this 
  <a href="http://imageshack.us/photo/my-images/443/reportw.jpg/" rel="nofollow">http://imageshack.us/photo/my-images/443/reportw.jpg/</a></p>
  
  <p>Generated from three database tables depends on student ID</p>
  
  <p><a href="http://img51.imageshack.us/img51/1272/tablesh.jpg" rel="nofollow">http://img51.imageshack.us/img51/1272/tablesh.jpg</a></p>
  
  <p>So i want to display this table without any fixed value of exams or subjects .. i did it by this way and it is working good but i hope to know if it is the best way or not </p>
  
  <pre><code> &lt;? 
  
  
  $con = mysql_connect("localhost","root","123"); 
  if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
     } 
  mysql_select_db("test", $con); 
  
  
  //////////////////////// 
  
  
  
  ///////////////// Select the exams and put it in array  
  $ex = mysql_query("SELECT * FROM exams");  
  $dc=1; 
  while ($rowex= mysql_fetch_array($ex)){ 
  $exn[$dc]=$rowex['Exam_Title']; 
  $exid[$dc]=$rowex['Exam_ID']; 
  $dc++; 
  } 
  
  
  /////////////////////////// Select the subjects and put it in array  
  $sj = mysql_query("SELECT * FROM subjects");  
  $dsj=1; 
  while ($rowsj= mysql_fetch_array($sj)){ 
  $sjn[$dsj]=$rowsj['Subj_Title']; 
  $sjid[$dsj]=$rowsj['Subj_ID']; 
  $dsj++; 
  } 
  
  ////////////////Select the student marks and put it in array with subject id and exam id 
  
  $result = mysql_query("SELECT * FROM stu_marks");  
  while ($row= mysql_fetch_array($result)){ 
  $arr[$row['Subj_ID']][$row['Exam_ID']]=$row['Grade']; 
  
  } 
  /////////////////////// count the exams and the subjects to draw the table 
   $exc=count($exn); 
   $sjc=count($sjn); 
   ?&gt; 
  
   &lt;table width="400" border="1"&gt; 
    &lt;tr&gt; 
  
  
  
      &lt;? 
  ///////// display subjects in table rows 
  for ($d=0;$d&lt;=$sjc;$d++){ 
  
  if ($d==0){ 
      echo '&lt;td&gt;-&lt;/td&gt;'; 
  }else{ 
      echo ' &lt;tr&gt;&lt;td&gt;'.$sjn[$d].'&lt;/td&gt;'; 
  } 
  
   ///////// display exams in table head tds  
  
  for ($p=1;$p&lt;=$exc;$p++){ 
  if ($d==0){ 
      echo '&lt;td&gt; '.$exn[$p].'&lt;/td&gt;'; 
  }else{ 
  ?&gt; 
   &lt;td&gt; 
  
   &lt;?=$arr[$sjid[$d]][$exid[$p]]?&gt; 
  
   &lt;/td&gt; 
    &lt;?} 
    } 
   }?&gt; 
  
    &lt;/table&gt;
  </code></pre>
  
  <p>i asking just if this is a good way to do this</p>
  
  <p>sorry for my English language</p>