• Register
Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the tech & programming Question that you want. Guests Posting are allowed.
+3 votes
46 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>

<html>

<head>

</head>

in PHP by (320 points) 5 17
Your language is so weak. Kindly describe with exact language.
Please try to write in exact language. I have added an answer, hope will help you.

2 Answers

+2 votes

You should use SUM with MYSQL database column . 

Try this code and get sum of column . 

$sql = mysqli_query($mysqli,"SELECT SUM(column_name) as total FROM table_name");

$row = mysql_fetch_array($sql); 

$sum = $row['total']; . 

by (5k points) 4 15 45
<?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
First check this code is working or not . Tell if the code works for you .
Yes that code I post its correctly working
You can add this code , where you want to use inside the HTML table .
+1 vote

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 the sum of all complete column. 

<?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 connection config file. 

2. If you want to sum then, change 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. 

by (7k points) 4 20 45
Bhai When I Enter The Code and Changed Sum(ObtainedMarks) The Result is 1452 Then In Querry 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
Please Solve
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 .
...