2015-09-07 70 views
0

我建立了一个表格,用户可以输入国家名称和国家的拨号代码。该表单提交给数据库,然后从表中显示国家名称,国家的拨号代码和另外两个选项EDIT和DELETE(具有GET URL链接,例如www.abc.com/country.php?country=Pakistan )PHP动态表与编辑/删除链接打开弹出

我想添加AJAX到它,以便当用户点击编辑或删除链接相关的弹出式打开与GET URL中的数据。

以下是我的动态表在PHP

<div> 
<?php 
    $q = "SELECT * FROM country"; 
    $result = mysqli_query($conn, $q); 
    echo "<table border=2><tr><th>Country Name</th><th>Country Code</th><th></th><th></th></tr>"; 

    while($a = mysqli_fetch_array($result)) { 
     $cn = $a['cname']; 
     $cc = $a['ccode']; 
?> 
<tr> 
<td><?php echo $cn ?></td> <td><?php echo $cc; ?></td> 
<script type="text/javascript"> 
    var a = 0; 
    var cname = new Array("<?php echo $cn;?>"); 
    a++; 
</script> 
<td> 
    <a href='#' onclick='javascript:editWin(cname[a]); return(false);'>Edit</a> 
</td> 
<td id="<?php echo $cn;?>"> 
    <a href='#' onclick='javascript:delWin(); return(false);'>Remove</a> 
</td> 
</tr> 
<?php  
    } 
?> 
</div> 

我的外部JavaScript函数如下

function editWin(e) { 
    window.open('edit.php?country='+e,'','height=400, width=600, top=100, 
       left=400, scrollable=no, menubar=no', ''); 
}; 

在此网址它说不确定的弹出窗口打开时。

+4

你尝试过什么吗? –

+0

你可以使用jQuery和模态插件进行模态对话 - 这里有大量的插件。做一个搜索引擎搜索? – halfer

+0

我编写了一个代码来从数据库中获取数据,并在表格中显示以及编辑和删除的链接。 我认为在JavaScript中可以有一个函数,我可以在点击时解析动态链接,该函数会弹出一个可以实现操作的页面。 这是我的想法 –

回答

0

我得到了解决

我的PHP代码如下

<div> <?php 

        $q = "SELECT * FROM country"; 
        $result = mysqli_query($conn, $q); 

        echo "<table border=2><tr><th>Country Name</th><th>Country Code</th><th></th><th></th></tr>"; 

        while($a = mysqli_fetch_array($result)) { 

           $cn = $a['cname']; 
           $cc = $a['ccode']; 
           ?> 


          <tr> 

          <td><?php echo $cn ?></td> <td><?php echo $cc; ?></td> 
          <td><a href='#' id="<?php echo $cn; ?>" onclick='javascript:editWin(this.id); return(false);'>Edit</a></td> 
          <td><a href='#' id="<?php echo $cn; ?>" onclick='javascript:delWin(this.id); return(false);'>Remove</a></td></tr> 
        <?php  

        } 

      ?> 
    </div> 

和我的JavaScript如下

function editWin(e) { 
window.open('edit.php?country='+e,'','height=400, width=600, top=100, left=400, scrollable=no, menubar=no', ''); 
};        

function delWin(e) { 
window.open('del.php?country='+e,'','height=400, width=600, top=100, left=400, scrollable=no, menubar=no', ''); 
};