2017-02-15 16 views
1

私はいくつかのコードを持って、次を参照してください。jqueryのUIダイアログにクエリ文字列(テーブルのtr TD)foreachの行から値を取得

<script> 
 
    $$.ready(function() { \t \t \t \t 
 
    // Profile Dialog 
 
\t \t \t \t 
 
    $("#user-dialog").dialog({ 
 
    autoOpen: false, 
 
    modal: true, 
 
    width: 400, 
 
    open: function(){ $(this).parent().css('overflow', 'visible'); $$.utils.forms.resize() } 
 
    }).find('button.submit').click(function(){ 
 
    var $el = $(this).parents('.ui-dialog-content'); 
 
    if ($el.validate().form()) { 
 
     $el.dialog('close'); 
 
    } 
 
    }).end().find('button.cancel').click(function(){ 
 
    var $el = $(this).parents('.ui-dialog-content'); 
 
    $el.find('form')[0].reset(); 
 
    $el.dialog('close');; 
 
    }); 
 
\t \t \t \t \t \t \t 
 
    $('#user-table').on('click', '.open-user-dialog', function(){ 
 
    $("#user-dialog").dialog("open"); 
 
    return false; 
 
    }); 
 
}); 
 
</script>
<table id="user-table"> 
 
<thead> 
 
    <tr> 
 
    <th>id</th> 
 
\t <th>name</th> 
 
\t <th>action</th> 
 
    </tr> 
 
</thead> 
 
<tbody> 
 
<?php 
 

 
$sql = "SELECT id,user_name FROM users"; 
 

 
if ($result = $verbindung->query($sql)) { 
 
while ($row = $result->fetch_assoc()) { 
 
?>   
 
    <tr> 
 
    
 
\t <td><?php echo $row["id"];?></td> 
 
    <td><?php echo $row["user_name"];?></td> 
 
    <td> 
 
     <button class="open-user-dialog"><img src="img/icons/packs/fugue/16x16/bullet_go.png"/> view</button>      
 
    </td> 
 

 
\t </tr> 
 
\t <?php }} \t ?> 
 
\t 
 
    </tbody> \t 
 
</table> 
 

 
<div style="display: none;" id="user-dialog" title="user view"> 
 
\t \t \t \t 
 
\t \t <form action=""> 
 

 
\t \t \t <div class="row"> 
 
\t \t \t \t <label> 
 
\t \t \t \t \t <strong>User details</strong> 
 
\t \t \t \t </label> 
 
\t \t \t \t <div> 
 
\t \t \t <input type="text" id="user_id" value="<?php echo $id; ?>"> 
 
\t \t \t <input type="text" id="user_name" value="<?php echo $user_name; ?>">        
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t </form> 
 
\t \t 
 
\t \t <div class="actions"> 
 
\t \t \t <div class="left"> 
 
\t \t \t \t <button class="grey cancel">cancel</button> 
 
\t \t \t </div> 
 
\t \t \t <div class="right"> 
 
\t \t \t \t <input id="submit" onclick="userFunction()" type="button" value="go"> 
 
\t \t \t </div> 
 
\t \t </div> \t \t \t \t 
 
</div>
私は私のjqueryのダイアログにテーブルから私の詳細を取得する方法

ダイアログが正常に動作していますが、$ row ['id']と$ row ['user_name']の値がjqueryダイアログに表示されません。

私が試しているのは、私はダイアログ内のデータをさらに処理することができません。

どのようにして、各行に$ row ['id']と$ row ['user_name']をダイアログに渡すことができますか?

誰か助けてもらえますか?

答えて

0

まず、phpタグでPHPコードを追加します。あなたはphpでifとwhileを記述しません。

<table> 
<thead> 
<tr> 
<th>id</th> 
<th>name</th> 
<th>action</th> 
</tr> 
</thead> 
<tbody> 
<?php 
if ($result = $verbindung->query($sql)) { 
while ($row = $result->fetch_assoc()) { 
?>  
<tr> 

<td><?php echo $row["id"];?></td> 
<td><?php echo $row["user_name"];?></td> 
<td> 
    <button class="open-user-dialog"><img src="img/icons/packs/fugue/16x16/bullet_go.png"/> view</button>      
</td> 

    </tr> 
    <?php }} ?> 

    </tbody> 
    </table> 

    <div style="display: none;" id="user-dialog" title="user view"> 

       <form action=""> 

        <div class="row"> 
         <label> 
          <strong>User details</strong> 
         </label> 
         <div> 
       <input type="text" id="user_id" value="<?php echo $id; ?>"> 
<input type="text" id="user_name" value="<?php echo $user_name; ?>">        
         </div> 
        </div> 
       </form> 

       <div class="actions"> 
        <div class="left"> 
         <button class="grey cancel">cancel</button> 
        </div> 
        <div class="right"> 
         <input id="submit" onclick="userFunction()" type="button" value="go"> 
        </div> 
       </div>    

これが答えではない、この

+1

を試してみてください、これはコメントであり、そのよう記述する必要があります。 –

+0

このコメンタントは私を助けません、他の誰かが私のための解決策を持っていますか? – Peisi

関連する問題