Javascript PHP和引导模式变量

Javascript PHP和引导模式变量,javascript,php,twitter-bootstrap,modal-dialog,Javascript,Php,Twitter Bootstrap,Modal Dialog,希望任何人都能帮助我。 我的数据有一个带有while语句的表。现在,我希望在模式窗口中显示每一行的数据 <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>ID</th> <th>Marke</th> <th>Modell</th

希望任何人都能帮助我。 我的数据有一个带有while语句的表。现在,我希望在模式窗口中显示每一行的数据

<table id="example1" class="table table-bordered table-striped">
<thead>
    <tr>
        <th>ID</th>
        <th>Marke</th>
        <th>Modell</th>
        <th>Baujahr</th>
        <th>Aktion</th>
    </tr>
</thead>
<tbody>';
// Holen des Ergebis in die Variable $erg
while($erg_motor = mysqli_fetch_assoc($db_erg_motor))
#print_r($erg_motor);
{
    $body.='
    <tr>
        <td>'.$erg_motor['id'].'</td>
        <td><input name="motor_fabrikat" value="'.$erg_motor['motor_fabrikat'].'"></td>
        <td><input name="motor_modell" value="'.$erg_motor['motor_modell'].'"></td>
        <td><input name="motor_ez" value="'.$erg_motor['motor_ez'].'"></td>
        <td><button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Edit</span></button></td>
    </tr>
    ';

}
$body.='
</tbody>
<tfoot>
    <tr>
        <th>ID</th>
        <th>Marke</th>
        <th>Modell</th>
        <th>Baujahr</th>
        <th>Aktion</th>
    </tr>
</tfoot>

身份证件
马克
模特儿
鲍加尔
阿基翁
';
//变量$erg中的霍伦·德斯尔格比
而($erg_motor=mysqli_fetch_assoc($db_erg_motor))
#印刷机(erg_电机);
{
$body.='
“.$erg_马达['id']”
编辑
';
}
$body.='
身份证件
马克
模特儿
鲍加尔
阿基翁

和我的模态窗口的代码

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Interne Vorgangsnummer: </h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary">Speichern</button>
            </div>
        </div>
    </div>
</div>

&时代;
接近
沃甘斯努默实习生:
斯皮切恩

现在我想在模态体中显示我的唯一键
$erg_motor['id']
。稍后我想更新包含到
$erg_motor['id']

的数据,while语句必须包装在 变量也必须包装在

以下是使用foreach的示例:

<!DOCTYPE html>
<html>
<head>
    <title>dynamic data</title>
</head>
<body>
<h2>Dynamic data</h2>
    <?php $arr = array('a','b','c','d'); ?>
    <ul>
        <?php foreach ($arr as $key => $val): ?>
            <li><?php echo $val; ?></li>
        <?php endforeach ?>
    </ul>
</body>
</html>

动态数据
动态数据

这里有两个选项:

  • 为表的每一行创建一个模式(错误)
  • 使用JS/jQuery获取单击行的id,并将
    $erg_motor['id']
    填充到模式中
  • 一个例子为2。将是:

    在循环内部,将tr更改为如下所示:

    <tr data-row-id='<?= $erg_motor['id'] ?>'>
    
    在这之后,我想您将在该模式中拥有一个编辑表单,因此只需使用jQuery来处理后期编辑,然后使用
    $('tr[data row id=“the-id-FROM-the-SPAN”]”)相应地更改行的数据。


    至少我是这样做的。

    以下是表格的代码:

    <table id="example1" class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Marke</th>
                                            <th>Modell</th>
                                            <th>Baujahr</th>
                                            <th>Aktion</th>
                                        </tr>
                                    </thead>
                                    <tbody>';
                                    // Holen des Ergebis in die Variable $erg
                                    while($erg_motor = mysqli_fetch_assoc($db_erg_motor))
                                    #print_r($erg_motor);
                                    {
                                        $body.='
                                        <tr data-row-id='.$erg_motor['id'].'>
                                            <td>'.$erg_motor['id'].'</td>
                                            <td><input name="motor_fabrikat" value="'.$erg_motor['motor_fabrikat'].'"></td>
                                            <td><input name="motor_modell" value="'.$erg_motor['motor_modell'].'"></td>
                                            <td><input name="motor_ez" value="'.$erg_motor['motor_ez'].'"></td>';
                                    $body.='<td><button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Edit</span></button></td>';
    
    
                                        $body.='</tr>';
                                    }
                                    $body.='
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>ID</th>
                                            <th>Marke</th>
                                            <th>Modell</th>
                                            <th>Baujahr</th>
                                            <th>Aktion</th>
                                        </tr>
                                    </tfoot>
                                </table>
    
    
    身份证件
    马克
    模特儿
    鲍加尔
    阿基翁
    ';
    //变量$erg中的霍伦·德斯尔格比
    而($erg_motor=mysqli_fetch_assoc($db_erg_motor))
    #印刷机(erg_电机);
    {
    $body.='
    “.$erg_马达['id']”
    ';
    $body.='Edit';
    $body.='';
    }
    $body.='
    身份证件
    马克
    模特儿
    鲍加尔
    阿基翁
    
    是否考虑动态执行?你有例子吗?首先。非常感谢。我不确定我是否正确。泽特佩尔:23.10.2014 12:49:39费勒:SyntaxError:失踪;在语句Quelldatei:Quelltext:var行id=$(this.closest(“tr”).attr(“数据行id”)之前;我将
    var row id
    更改为
    var row\u id
    ,现在应该可以工作了,祝你好运。错误:ReferenceError:row未定义->其余工作正常。我的tr标签上有id。但我似乎认为变量没有发送到脚本。你有什么想法吗?
    <table id="example1" class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Marke</th>
                                            <th>Modell</th>
                                            <th>Baujahr</th>
                                            <th>Aktion</th>
                                        </tr>
                                    </thead>
                                    <tbody>';
                                    // Holen des Ergebis in die Variable $erg
                                    while($erg_motor = mysqli_fetch_assoc($db_erg_motor))
                                    #print_r($erg_motor);
                                    {
                                        $body.='
                                        <tr data-row-id='.$erg_motor['id'].'>
                                            <td>'.$erg_motor['id'].'</td>
                                            <td><input name="motor_fabrikat" value="'.$erg_motor['motor_fabrikat'].'"></td>
                                            <td><input name="motor_modell" value="'.$erg_motor['motor_modell'].'"></td>
                                            <td><input name="motor_ez" value="'.$erg_motor['motor_ez'].'"></td>';
                                    $body.='<td><button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Edit</span></button></td>';
    
    
                                        $body.='</tr>';
                                    }
                                    $body.='
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>ID</th>
                                            <th>Marke</th>
                                            <th>Modell</th>
                                            <th>Baujahr</th>
                                            <th>Aktion</th>
                                        </tr>
                                    </tfoot>
                                </table>