将选中的复选框值相加并显示在另一个字段中

时间:2018-01-14 23:12:33

标签: php html mysql

我使用选择框和html表中的搜索按钮从每行的复选框中获取数据库表(测试)中的数据,

我想添加选中复选框的费用,并在价格字段中播种价格。

当我在(折扣)字段中输入折扣值时,这将根据价格计算折扣并在(折扣后)字段中显示最终价格 和时间应该是和时并显示在时间字段中。

我还希望在另一次搜索后,选中的复选框行应保留在视图中,因为选中的复选框行在另一次搜索后不会保留在视图中。并且在经过另一次搜索并检查检查之后,应该将价格添加到相同的价格中,以便在折扣和时间之后折扣相同

毕竟我想在另一个表(注册表)中提交这些数据。

test table: fetching data register  table : inserting data view

<div class ="table-responsive">
    <table class="table table-bordered" id="table1">
        <tr>
            <form method='post'>
                <td><select name="group" style="width:100%;" required="">
                        <option value="" selected disabled hidden>select .....</option>
                        <option>General</option>
                        <option>HEAMATOLOGY</option>
                        <option>BIO CHEMISTRY</option>
                        <option>DIABEIC PROFILE</option>
                        <option>SEROLOGY</option>
                        <option>CBC</option>
                        <option>BLOOD EXAMINATION</option>
                        <option>ARTHRITIS PROFILE</option>
                        <option>URINE EXAMINATION PROFILE</option>
                        <option>LIPID PROFILE</option>
                        <option>KIDNEY FUNCTION TEST</option>
                        <option>LIVER FUNCTION TEST </option>
                        <option>OLT</option>
                        <option>URINE EXAMINATION</option>
                        <option>SEMEN ANALYSIS</option>
                        <option>PLEURAL FLUID/SYNOVIAL FLUID/C.S.FULID</option>
                        <option>PBF</option>
                        <option>STOOL EXAMINATION </option>
                        <option>MICROBIOLOGY</option>
                        <option>ELECTROLYTES TEST</option>
                        <option>HEAMOGRAM</option>
                        <option>SEMEN EXAMINATION</option>
                    </select></td>
                <td><input type='submit' name="search" id="search" value="search" class="btn btn-success btn-lg btn-block"></td>
            </form>
        </tr> 
    </table>
</div>
<?php 
$conn=mysqli_connect("localhost","root","","laboratory");
if(isset($_POST['search'])){
    $search=$_POST['group'];
    $query="SELECT * FROM test WHERE test_cata LIKE '$search' ";
    $db=mysqli_query($conn,$query);
    while ($run=mysqli_fetch_array($db)) {
        $name=$run['test_name'];
        $time=$run['test_time'];
        $charge=$run['test_charge'];
?>

<table border="1" class ="table-responsive" cellspacing="2" cellpadding="2">
    <tr>
        <td><?php echo $name;?></td>
        <td><?php echo $time;?></td>
        <td><?php echo $charge;?></td>
        <td><input type="checkbox" name="choice" id="choice" /></td>
    </tr>

<?php } 
} ?>

</table>

<div class="row">
    <div class="col-md-4">
        <div class="form-group">
            <label for="decimal">Price (₦) <span class="text-danger">*</span> </label>
        </div> 
        <input type="text" class="form-control input-sm"  name="total" id="total" placeholder=" Price" value="0" readonly="" >   
    </div>

    <div class="col-md-4">
        <div class="form-group">
            <label for="int">Discount (%) </label>
        </div>
        <input type="text" class="form-control input-sm" name="discount" id="discount" placeholder="Discount eg:(10)" value="0">        
    </div>

    <div class="col-md-4">
        <div class="form-group">
            <label for="decimal">After Discount <span class="text-danger">*</span> </label>
        </div> 
        <input type="text" class="form-control input-sm" name="total_price" readonly="" id="total_price" placeholder="Total Price" value="0">      
    </div>

    <div class="col-md-4">
        <div class="form-group">
            <label for="decimal">Total Time <span class="text-danger">*</span> </label>
        </div> 
        <input type="text" class="form-control input-sm" name="total_time" readonly="" id="total_time" placeholder="Total Time" value="0">   
    </div>
</div>
<input type="submit" name="submit" class="btn btn-primary" value="Book"/>
<input type="reset" value="Reset" class="btn btn-warning">
<a href="../dashboard/dashboard.php" class="btn btn-danger">Cancel</a>

</form>
</div>

0 个答案:

没有答案