Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么window.open php获取变量每次都获取相同的id,而不是剩余的条目?_Javascript_Php - Fatal编程技术网

Javascript 为什么window.open php获取变量每次都获取相同的id,而不是剩余的条目?

Javascript 为什么window.open php获取变量每次都获取相同的id,而不是剩余的条目?,javascript,php,Javascript,Php,在代码中,$fetch['id']工作正常,在其他地方,但在窗口中。打开它总是使用相同的值,即id号25,而不是其他id,我不明白为什么会这样……请帮助 $i=1; while ($fetch = mysql_fetch_array($data_qry)) { echo $url = $_SERVER['REQUEST_URI']."/edit_user_comment.php?id=".$fetch['id']; // here variable working fine....

在代码中,$fetch['id']工作正常,在其他地方,但在窗口中。打开它总是使用相同的值,即id号25,而不是其他id,我不明白为什么会这样……请帮助

$i=1;
while ($fetch = mysql_fetch_array($data_qry))
{
    echo $url = $_SERVER['REQUEST_URI']."/edit_user_comment.php?id=".$fetch['id']; // here variable working fine....
    echo "<tr>";
    echo "<td>".$i."</td>";
    echo "<td>".$fetch['comp_name']."</td>";
    if (strlen($fetch['comp_add'])> 10)
    {
        echo "<td>".substr($fetch['comp_add'], 0, 10)."...";
    }else{
        echo "<td>".$fetch['comp_add'];
        }"</td>";
    echo "<td>".$fetch['business_registration_no']."</td>";
    echo "<td>".$fetch['email_id']."</td>";
    echo "<td>".$fetch['tel_no']."</td>";
    echo "<td>".$fetch['fax']."</td>";
    echo "<td>".$fetch['prsn_in_chrg']."</td>";
    echo "<td>".$fetch['ph_no']."</td>";
    ?>
    <script>
    function windowopen(){
                window.open('<?= $url; ?>','Comment Edit', 'menubar=1,location=1,status=1,scrollbars=yes,width=500, height=500');
                //here it is takin $fetch['id']=25 only and not other ids, i want to know the mistake i m doing here... Please help
            }
    </script>
    <?php       
    if($fetch['comments']!='')
    {
        echo "<td><textarea name='comments' id='id_comments'>".$fetch['comments']."</textarea>
    <a onclick='return windowopen();' class='button button-primary button-large edit'>Edit</a></td>";
    }else{ 
        echo "<td><a onclick='return windowopen();' class='button button-primary button-large'>Add Comment</a></td>";
    }       
    echo "<td> <a href='response.php?id=".$fetch['id']."&action=approve' class='button button-primary button-large approve'>Approve</a> <a href='response.php?id=".$fetch['id']."&action=dissapprove' class='button button-primary button-large'>Dissapprove</a> </td>";
    echo "</tr>";       
        $i++;
}

这是因为您正在重新声明相同的函数windowopen,因此最后一个声明将覆盖其他声明,并且您为所有元素获得相同的函数来详细说明我之前的注释-生成的链接应类似于:

echo '<td><a onclick="return windowopen(\''.$url.'\');">Add Comment</a></td>';
…并且您的函数应该在循环之外声明一次,如下所示:

<script>
function windowopen(url)
{
      window.open(url,'Comment Edit', '/*blah*/');
}
</script>
在while循环之外声明一次windowopen函数,然后在单击链接时使用作为参数传递的URL调用该函数。