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
How to add row in loop
Moderator: General Moderators
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
How to add row in loop
- Attachments
-
- marks.JPG (56.76 KiB) Viewed 246 times
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: How to add row in loop
Try this:
Take note of the changes I made. Also, please use the
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);
?>Code: Select all
tags when posting code here.-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: How to add row in loop
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.............
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.............