×

Please Login or Register to continue.

3
(1.6K Views)

I want to sum of OBTAINED MARKS OF related RollNo 1,2,3,4 Etc

When I write RollNo So The All subject came On Table And Sum its ObtainedMarks

This is My Code:- Please Solution

 

  <body>
    <br/><br/>
   <form action="" method="post" name="form1">
        <table width="25%" border="0">
            <tr>
                <td>RollNo</td>
                <td><input type="number" min = 1  name="RollNo"></td>
            </tr>
<tr><td> 
<?php 
$cser=mysqli_connect("localhost","root","","dmc") or die("connection failed:".mysqli_error());
$result = mysqli_query($cser,"SELECT Subject FROM subjects") or die(mysql_error());
if (mysqli_num_rows($result)!=0)
{
echo 'Subject</td><td><select name="Subject">
      <option value=" " selected="selected">Choose one</option>';
   while($drop_2 = mysqli_fetch_array( $result ))
{
  echo '<option value="'.$drop_2['Subject'].'">'.$drop_2['Subject'].'</option>';
}
echo '</select>';
}
?>
</td>
</tr> 
       <tr>
                <td>Name</td>
                <td><input type="text" pattern="[a-zA-Z][a-zA-Z ]{2,}"  name="Name"></td>
            </tr>
            <tr>
                <td>ObtainedMarks</td>
                <td><input type="number" min = 1 name="ObtainedMarks"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="Submit" value="Enter"></td>
            </tr>
        </table>
    </form>
</body>
</html>

 

(90 Points)
in PHP

Share

2 Answers
(9.4K Points)
1

I am not getting your point. Your language is not readable format. Well if you want to sum of obtained marks column data using PHP, then follow this code. It will help you with the sum of all complete columns. 

<?php 
$cser=mysqli_connect("localhost","root","","test") or die("connection failed:".mysqli_error());
$sql_qry="SELECT SUM(pprice) AS count FROM crud2";
$duration=mysqli_query($cser,$sql_qry);
while($record = $duration->fetch_array()){
    $total = $record['count'];
}
echo $total
?>

1. Change MySQL database name (test to your db name )  or do not add this line if you are already added the connection config file. 

2. If you want to sum then, change the crud2 table name to your created table name. 

3. If you want to sum of obtained marks, change pprice to your obtained marks column name. 

I hope, it will you. If the problem will occur, then comment here. 


Comment
When I enter the code and changed sum(ObtainedMarks) the Result is 1452 Then In Query I Add GROUP BY RollNo So The Answer is 267 it is the marks of rollno 6 where is 1 2 3 4 5 rollno marks how can I check that marks
osama 07 Sep 2019
Please Solve
osama 07 Sep 2019
You can use while loop to get data one by one and sum .Do you want to sum of all column data . Use while loop and sum logic .
shakti 07 Sep 2019

(7.3K Points)
2

You should use SUM with the MYSQL database column. 

Try this code and get the sum of the column. 

$sql = mysqli_query($mysqli,"SELECT SUM(column_name) as total FROM table_name");
$row = mysql_fetch_array($sql); 
$sum = $row['total']; . 

 


Comment
<?php //including the database connection file $cser=mysqli_connect("localhost","root","","dmc") or die("connection failed:".mysqli_error()); //fetching data in descending order (latest entry first) $result = mysqli_query($cser, "SELECT * FROM marks ORDER BY RollNo "); // using mysqli_query instead ?> <html> <head> <title>Homepage</title> </head> <body background="bk3.v1 (1).jpg"> <div class="myBox"> <table border=2 > <tr bgcolor='grey'> <td>RollNo</td> <td>Name</td> <td>Subject </td> <td>ObtainedMarks </td> <td>Remove </td> <td>Update</td> </tr> <?php while($res = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>".$res['RollNo']."</td>"; echo "<td>".$res['Name']."</td>"; echo "<td>".$res['Subject']."</td>"; echo "<td>".$res['ObtainedMarks']."</td>"; echo "<td><a href=\"delete1.php?id=$res[id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>"; echo "<td><a href=\"edit1.php?id=$res[id]\"><input type='submit' value='Edit'></a>"; echo "</tr>"; } ?> </table> </div> </body> </html> this is my code where i used i dont know plz help
osama 07 Sep 2019
First check this code is working or not . Tell if the code works for you .
vishalrana1 07 Sep 2019
Yes that code I post its correctly working
osama 07 Sep 2019
You can add this code , where you want to use inside the HTML table .
vishalrana1 07 Sep 2019

Related Questions :-

Featured Items:-


Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65



Result management system with Marksheet in PHP website | PHP Scripts

$39




Your Answer

You can post your answer after login..