从查询字符串(表tr td)foreach行获取值到jquery ui对话框

时间:2017-02-15 07:53:08

标签: javascript php mysql

我有一些代码,请参阅:

<script>
  $$.ready(function() {				
  // Profile Dialog
				
  $( "#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');;
  });
							
  $('#user-table').on('click', '.open-user-dialog', function(){
    $( "#user-dialog" ).dialog( "open" );
    return false;
  });
});
</script>
<table id="user-table">
<thead>
    <tr>
    <th>id</th>
	<th>name</th>
	<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>
    
	<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>				
</div>

我如何从表格到jquery对话框获取我的详细信息?

对话框工作正常,但我没有在$ jquery对话框中显示$ row ['id']和$ row ['user_name']的值。

我也尝试了,我没有在对话框中获取数据以便能够进一步处理它们。

如何将每行的$ row ['id']和$ row ['user_name']传递给我的对话框?

有人能帮帮我吗?

1 个答案:

答案 0 :(得分: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>              

试试这个