如何在这个模态div中显示这个.php文件



现在,当我单击链接时,它会转到链接。工作良好。但是如何在下面的div(modal)中显示posts.php呢。

我不想离开index.php。如果它是一个普通的.php文件,我只需要插入它,它就会出现在模态中。

这里简单的include不起作用,因为我需要在posts.php中传递id才能获得确切的帖子。

我该怎么办?

index.php

<li data-toggle="modal" data-target="#myModal"><a href="posts.php?id=<?=$post_id?>"  >show post</a></li>

<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Post</h4>
</div>
<div class="modal-body">

		<div >




// I need  show posts.php  inside here
		
		
	


		
		</div>
		
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

posts.php

<?php 
include("connect.php");
	
$post_id = $_GET['id'];
$get_post = " SELECT * FROM `posts` where post_id='$post_id' ";
$run_post = mysql_query($get_post);
	
while ($row=mysql_fetch_array($run_post)){
	
	
		$post_title = $row['post_title'];
		
		$post_image = $row['post_image'];
		
	}
?>
<p> <?php echo $post_title;?></p>
<img  src="images/<?php echo $post_image;?>" />

这里基本上有三种选择:

include/require

您可以使用关键字includerequire来告诉PHP基本上在当前文件中运行另一个PHP文件的内容,如下所示:

<?php
$foo = "bar";
include "othercode.php"; //or alternatively: require "othercode.php";
echo "$foo + $variableinothercode";
?>

includerequire的区别在于,如果找不到文件,require将抛出严重错误,而include只会抛出警告。


iFrame

我不推荐这个选项;然而,它的一个选项,所以我无论如何都会包括它;

您可以简单地将<div>标记替换为<iframe>,并将其src属性设置为文件的位置,如下所示:

<iframe src="http://example.com/othercode.php"></iframe>

将代码复制/剪切到文件中

总有一种选择是通过将文件的内容复制或剪切到新文件中来冗余另一个文件,但只有当文件没有被包括或在其他地方使用时,才应该这样做,因为它会破坏这些脚本;简单的CCD_ 12或CCD_。

最新更新