Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:30:26+00:00 2026-05-26T01:30:26+00:00

I have a PHP page displaying the results of a MySQL query. It adds

  • 0

I have a PHP page displaying the results of a MySQL query. It adds checkboxes to each row. The selected rows are then inserted into another table on submit.

My application is a Transport planning platform. I am looking for a way to display the total weight of the selected rows in real time, a box at the top of the page dispalying the current sum of the selected rows.

Can anybody guide me on how to add this functionality to my existing page.

My code currently is shown below:

<?php
    mysql_connect("localhost", "username", "password")or die("cannot connect");    
    mysql_select_db("databasename")or die("cannot select DB");
    $sql="SELECT `crtd dept`,`customer`,`case no`,`gross mass` from despgoods_alldetails where transporttypename= 'localpmb'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
?>
<table border=1>
    <tr>
        <td>
            <form name="form1" method="post">
                <table>
                    <tr>
                        <td>#</td>
                        <td>Dispatch Area</td>                      
                        <td>Customer</td>  
                        <td>Case Number</td>
                        <td>Weight</td> 
                    </tr>
<?php
    while($rows=mysql_fetch_array($result)){
?>
                    <tr>
                        <td><input type="checkbox" name=check[]  value="<?php echo $rows['case no']; ?>"></td>
                        <td><?php echo $rows['crtd dept']; ?></td>
                        <td><?php echo $rows['customer']; ?></td>
                        <td><?php echo $rows['case no']; ?></td>
                        <td><?php echo $rows['gross mass']; ?></td>
                    </tr>                                   

<?php
    }
?>
                    <tr>
                        <td colspan=3><input name="Next" type="submit" id="Next" value="Next"></td>
                    </tr>
                    <?php



                            $check=$_POST['check'];

                        if($_REQUEST['Next']=='Next'){
 {
                            $sql="INSERT INTO loaddetails (dispatcharea,Customer, casenumber, weight,LOCStatus) 
                            SELECT `crtd dept`,Customer,`case no`,`gross mass`,'in Load Creation'
                            FROM despgoods_alldetails WHERE `Case No` = '$val'";

                            foreach($check as $key=>$value)
                            {
                            $sql="INSERT INTO loaddetails (dispatcharea,Customer, casenumber, weight,LOCStatus)
                            SELECT `crtd dept`,Customer,`case no`,`gross mass`,'in Load Creation'
                            FROM despgoods_alldetails WHERE `Case No` = '$value'";
                            $final=mysql_query($sql);
                            if($final)
                            {
                            echo "<meta http-equiv=\"refresh\" content=\"0;URL=planlocalpmbstep2.php\">";
                            }                                            } 
                                }
                                }
                    // Check if delete button active, start this



// if successful redirect to php.php

mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>

The output of the above code is shown below:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:30:26+00:00Added an answer on May 26, 2026 at 1:30 am

    As the others have said, you’ll have to do this in Javascript, since it’ll be on the client side. I’ll assume that you’re not using a library such as jQuery or Prototype on this page, and if this is all you’re doing, it’d be massive overkill to use one of them.

    First, add a HTML element which will contain your total:

    <div>Total: <span id="total">0</span></div>
    

    The bit of information you really need to know however, is the weight which corresponds to each checkbox. The simplest method would be to store it on the checkbox element itself. Add an attribute called data-weight. eg:

    <input type="checkbox" name="check[]" value="12" data-weight="1234" />
    

    Then, add some javascript:

    <script>
        (function () {
            var totalEl = document.getElementById('total'),
                total = 0,
                checkboxes = document.form1['check[]'],
                handleClick = function () {
                    total += parseInt(this['data-weight'], 10) * (this.checked ? 1 : -1);
                    totalEl.innerHTML = total;
                },
                i, l
            ;
            for (i = 0, l = checkboxes.length; i < l; ++i) {
                checkboxes[i].onclick = handleClick;
            }
        }());
    </script>
    

    Aaaannd here’s a working demo for you! http://jsbin.com/ipeduf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php page displaying query results from mysql. This result is displayed
I'm working on a php/mysql page. I have the table displaying the results I
Well, I have a simple page displaying records from Database with PHP & MySQL.
I have a PHP page that is bringing in results from a Database and
I have a search form and am displaying the results on the same page
I have a web page and using php Im quering a database and displaying
I have a MSSQL database table I'm accessing on a PHP page. I'm displaying
I have a PHP-generated page which is displaying some data about a set of
I have a PHP page where i want to open a file on a
I have a PHP page that loads external content using other PHP files. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.