在代码中,$ fetch [' id']工作正常,但在window.open中,它取的值始终是id 25,而不是其他id,我可以&# 39;不明白为什么会这样....请帮助........
$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++;
}
答案 0 :(得分:0)
这是因为您正在重新声明相同的函数windowopen()
,因此最后一个声明会覆盖其他声明,并且您为所有元素提供了相同的功能
答案 1 :(得分:0)
详细说明我之前的评论 - 生成的链接应该类似于:
echo '<td><a onclick="return windowopen(\''.$url.'\');">Add Comment</a></td>';
...你的函数应该在循环之外声明一次,如:
<script>
function windowopen(url)
{
window.open(url,'Comment Edit', '/*blah*/');
}
</script>