donglin8467 2015-09-20 08:59 采纳率: 0%
浏览 41

克隆表行与PHP数据选择框

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

  • 写回答

1条回答 默认 最新

  • doutu9810 2015-09-20 09:21
    关注

    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...

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序