如何使用href将php变量值传递给div的iframe

时间:2015-06-22 06:06:02

标签: javascript php iframe



<?php
$query="SELECT * FROM `notification` where `Status`='1'  && `ownerid`='$userid' ";
$result = mysql_query($query);
$count=0;
while($row=mysql_fetch_array($result))
{
$nid=$row['notifid'];

$pr="select * from `Swap` where `notifid`='$nid'";
$prm=mysql_query($pr);
$prow=mysql_fetch_assoc($prm);
$rid=$prow['Requesterid'];

$query1="select * from `myuser` where `Userid`='$rid'";
//echo $query1;
$result1=mysql_query($query1);
$row1=mysql_fetch_assoc($result1);
$rname=$row1['Firstname'];
//echo $rname;
?>

<div style="width:100%; background: rgb(228, 228, 228);margin: 20px;padding: 20px;">
<h1>A New Swapping Request from <?php echo $rname; ?></h1>
Your sweater is choose for swapping.....you want to give permission?? 
  <div onclick="clicked(this);" id="<?php echo $nid; ?>">VIEW REQUEST</div>
</div>
<?php
$count++;
}
?>
  <div id="light" class="white_content" style="  height: auto;">
    <a href = "javascript:void(0)" style="background: #EAEAEA; padding: 5px 7px; color: #000; float: right;" onclick="confirmno()">X</a>
      <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

  <script type="text/javascript">
   function clicked(item) {
     document.getElementById('light').style.display='block';
     document.getElementById('fade').style.display='block';
     var a = $(item).attr("id");
   }
  </script>            
<div id="stylized" class="myform">
	<iframe width="100%" height="400px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="confirmed.php?x="+a> </iframe>  
		</div>

	</div>
&#13;
&#13;
&#13;

喜 在这里,我想通过href /任何其他传递唯一的PHP变量为i帧src传递。在看到教程的数量后,我得到$(项目).attr中的$ nid的值(&#34; id&#34;) ;但是如何将这个值传递给我试试你可以在我的代码中看到..但它不起作用的PLZ帮助

1 个答案:

答案 0 :(得分:0)

如果js位于单独的文件(.js)中,那么它不会被PHP解析,因此PHP标签将无法在那里工作。

在这种情况下,您可以通过2种方案来解决这个问题:

1)将函数声明移动到由PHP解析的文件(就像你的代码的第二个块,调用这个函数)

2)将输入参数添加到“confirmno”功能。参数设置“nid”值,它由PHP文件给出(而不是'onclick =“confirmno()'你会使用'onclick =”confirmno()'。

代码:

<script type="text/javascript">
    function confirmno(nid) {
    var con=confirm('You want keep this?');
    if (con == true) {
      window.location="notification.php";
    } else {
      window.location="confirmed1.php?nid=" + nid;
    }
}
</script>

<a href = "javascript:void(0)" style="background: #EAEAEA; padding: 5px 7px; color: #000; float: right;" onclick="confirmno(<?php echo $nid; ?>)">X</a>