So i want to display this table without any fixed value of exams or subjects … just i want the idea of looping
And is this the best way to insert the students marks?? coz by this way if i have 5000 student and 10 subjects and 12 exam in year … i will have mor than 500.000 record in table Stu_Marks
Welcome to the SP forums.
If you post the code you have so far, and then ask a specific question about something that is blocking you, then I’m sure someone will be willing to point you in the right direction.
And is this the best way to insert the students marks?? coz by this way if i have 5000 student and 10 subjects and 12 exam in year … i will have mor than 500.000 record in table Stu_Marks
Yes that’s the best way. You don’t have to worry about performance if you create the right indexes.
Hello dear
i don’t know where can i start … if i have array for exams and array for subjects and values depends on exam_id and subj_id
how can i use exam_id from the first loop to put it in the second one then display the grades ?
i will try to write a code to explain more
Please start by posting what you tried and we can see if any of your approaches work. We will not do this for you, but are glad to help, so please post your code.
Hello again
i did it by this way and i am not sure if it correct or no
<?
$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_grade");
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);
?>
<table width="400" border="1">
<tr>
<?
///////// display subjects in table rows
for ($d=0;$d<=$sjc;$d++){
if ($d==0){
echo '<td>-</td>';
}else{
echo ' <tr><td>'.$sjn[$d].'</td>';
}
///////// display exams in table head tds
for ($p=1;$p<=$exc;$p++){
if ($d==0){
echo '<td> '.$exn[$p].'</td>';
}else{
?>
<td>
<?=$arr[$sjid[$d]][$exid[$p]]?>
</td>
<?}
}
}?>
</table>