简体   繁体   中英

Clone Table Row With PHP Data Select Box

I am newbie in php as well as bootstrap. I am trying to create master-detail form to receive product from supplier. I had somehow manage to build the format but have difficulties on cloning table row with php select box. My HTML codes are below ...

<div class="form-group">
    <div class='row'>
        <div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
        <div class='col-xs-10 col-sm-10 col-md-10 col-lg-10'>
            <table class="table table-bordered table-hover" id="table-data">
                <thead>
                    <tr>
                        <th width="2%"><input id="check_all" class="formcontrol" type="checkbox"/></th>
                        <th width="38%">Parts Name</th>
                        <th width="15%">Price</th>
                        <th width="15%">Quantity</th>
                        <th width="15%">Total</th>
                    </tr>
                </thead>
                <tbody>
                    <tr id="id1" class="tr_clone">
                        <td><input class="case" type="checkbox"/></td>
                        <td>
                            <div class="dropdown">
                            <select data-type="partsCode" name="partsNo[]" id="partsNo1" class="form-control">
                            <?php
                            $query = "SELECT PARTS_ID, PARTS_NAME FROM parts_info ORDER BY PARTS_NAME";
                            if ($result = mysqli_query($con, $query))
                            {
                                while ($row = mysqli_fetch_array($result))
                                {
                                ?>
                                    <option value=<?php echo $row['PARTS_ID']; if ($shopid == $row['PARTS_ID']) echo " selected"; ?>> <?php echo $row['PARTS_NAME']; ?> </option>
                                <?php
                                }
                            }
                            mysqli_free_result($result);
                            ?>
                            </select>
                            </div>
                        </td>
                        <td><input type="number" name="price[]" id="price1" class="form-control changesNo" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                        <td><input type="number" name="quantity[]" id="quantity1" class="form-control changesNo" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                        <td><input type="number" name="total[]" id="total1" class="form-control totalLinePrice" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
    </div>
    <div class='row'>
        <div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
        <div class='col-xs-12 col-sm-3 col-md-3 col-lg-3'>
            <button class="btn btn-danger" type="button">- Delete</button>
            <button class="btn btn-success" type="button">+ Add More</button>
        </div>
        <div class='col-md-3 col-md-offset-4'>
            <button class="btn btn-primary btn-block" id="button" type="submit" name="submit" value="Submit">Save</button>
        </div>
        <div class='col-xs-1 col-sm-1 col-md-1 col-lg-1'> </div>
    </div>
</div>

Please anyone can solve my issue will be greatfull. I need to dynamically Add and Remove Row with this two buttons. Also if anyone have any reference on how to make master-detail form in php with bootstrap will support me well. Thank you in Advance.

To get a concept please check the following URL. I want to add Parts Name to Total as a new row when I press + Add More. Please note that the Parts Name comes from MySQL through PHP code ...

jsfiddle.net/imranctgbd/34djbLLn

Hi would have been helpful if there was a screenshot so i can fully understand your question. But here's what i fink you want to do.

to the cell holding ur delete checkbox, add , this means u have to create a delete.php and link it properly.

<td>  <a href='delete.php?id=$id' class='button small blue'>Delete</a> </td>

then here's what you do in your delete page

request id or whatever you want from your table and run a query. see example beneath

<?php
require_once('core.php');

$id = $_REQUEST['id'];
$sql = "delete from bookings where id = '$id'";
$result = mysqli_query($conn,$sql);

if ($result){


$count = mysqli_affected_rows($conn);

    if($count > 0){

            $redirect = header('location:index.php');
        echo $redirect;
        }

}
?>

same principle can be applied for addition or you could just use javascript for that dynamically...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM