为什么是窗口.打开PHP获取变量每次都获取相同的id,而不是剩余的条目


why is window.open php fetching variable is fetching same id every time and not the remaining entries?

在这里的代码中,$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++;
}

详细说明我之前的评论-生成的链接应该看起来像:

echo '<td><a onclick="return windowopen('''.$url.''');">Add Comment</a></td>';

…你的函数应该在循环外声明一次,像这样:

<script>
function windowopen(url)
{
      window.open(url,'Comment Edit', '/*blah*/');
}
</script>

这是因为您重新声明了相同的函数windowopen()所以最后的声明覆盖了其他的并且您得到了所有元素的相同函数