Page 1 of 1

How to add row in loop

Posted: Wed Nov 17, 2010 6:46 am
by manojsemwal1
Hi
I have trying to add total no of Marks in the last row of semester. but unable to add the row through loop.data are came from marks tb.

code are like
<?php



$sql="select SubjectCode,Subject,Theory,Practical,Total,Elective,SemId from subjectallocationtb where CourseId='$cours' order by PaperCode";

//echo $sql;
$rs=mysql_query($sql) or die (mysql_error());
$i=1;

$Lastid = "0";
$id = "";
while($count=mysql_fetch_array($rs))
{
if($count['SemId'] != $Lastid)
{
//echo "hai".$Lastid;
//echo $count['SemId'] ;
echo "<tr><td colspan='3'>$count[SemId]-Trimester</td><td></td><td></td></tr>";

//echo $Lastid;
//echo $count['SemId'] ;

$Lastid = $count['SemId'];
//echo $Lastid;


}

echo "hi";
//echo $Lastid;
//echo $count['SemId'] ;
$sql=mysql_query("select ObtMarks from studentmarkstb where RegistrationNo='$regd' and Course='$cours' and SubjectCode='$count[SubjectCode]'");

while($b=mysql_fetch_array($sql))
{
$marks = $b[ObtMarks];
}

//echo $marks;

echo "<tr><td>$i</td><td>$count[Subject]</td><td>100</td><td>40</td><td>$marks</td></tr>";

if($Lastid!= $id)
{
echo "total";
}

$i++;

//echo $count['SemId'];
//echo $Lastid;

}
//$rs=mysql_num_rows($sql);
?>
Find the attached file.............
thanks

Re: How to add row in loop

Posted: Wed Nov 17, 2010 11:54 am
by Jonah Bron
Try this:

Code: Select all

<?php



$sql="select SubjectCode,Subject,Theory,Practical,Total,Elective,SemId from subjectallocationtb where CourseId='$cours' order by PaperCode";

//echo $sql;
$rs=mysql_query($sql) or die (mysql_error());
$i=1;

$Lastid = "0";
$id = "";
$total = 0;
while($count=mysql_fetch_array($rs))
{
if($count['SemId'] != $Lastid)
{
//echo "hai".$Lastid;
//echo $count['SemId'] ;
echo "<tr><td colspan='3'>$count[SemId]-Trimester</td><td></td><td></td></tr>";

//echo $Lastid;
//echo $count['SemId'] ;

$Lastid = $count['SemId'];
//echo $Lastid;


}

echo "hi";
//echo $Lastid;
//echo $count['SemId'] ;
$sql=mysql_query("select ObtMarks from studentmarkstb where RegistrationNo='$regd' and Course='$cours' and SubjectCode='$count[SubjectCode]'");

while($b=mysql_fetch_array($sql))
{
$marks = $b[ObtMarks];
}

//echo $marks;

echo "<tr><td>$i</td><td>$count[Subject]</td><td>100</td><td>40</td><td>$marks</td></tr>";

$total += $marks;

if($Lastid!= $id)
{
echo "total";
}

$i++;

//echo $count['SemId'];
//echo $Lastid;

}

echo "<tr><td></td><td>Total</td><td>100</td><td>40</td><td>$total</td></tr>";
//$rs=mysql_num_rows($sql);
?>
Take note of the changes I made. Also, please use the

Code: Select all

 tags when posting code here.

Re: How to add row in loop

Posted: Wed Nov 17, 2010 11:44 pm
by manojsemwal1
Thanks for your reply........

i used this but it will sum the marks at end of the line but i need when the 1semester will finish the marks will add on the line and next semester line will start and add the marks of 2nd semester and add the total marks and add row of the end of semester.

like..........
1Trimester
sub1
sub2
sub3
total...................................Marks.
2Trimester
sub1
sub2
sub3
total...................................Marks.
3Trimester
sub1
sub2
sub3
total...................................Marks.

like this

thanks.............