简体   繁体   English

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

[英]How to show this .php file inside this modal div?

Now when I click the link it goes to link.现在,当我单击链接时,它会转到链接。 works fine.工作正常。 But how can I show posts.php inside the div(modal) below.但是如何在下面的 div(modal) 中显示 posts.php 。

I dont want to leave index.php .我不想离开 index.php 。 If it was a normal .php file I would simply inlcude and it would appear in the modal.如果它是一个普通的 .php 文件,我会简单地包含它,它会出现在模态中。

Here simple include does not work cause I need to pass the id in posts.php for getting the exact post.这里简单的包含不起作用,因为我需要在 posts.php 中传递 id 以获得确切的帖子。

what should I do ?我该怎么办 ?

index.php索引.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

 <?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;?>" />

You basically have three choices here:您在这里基本上有三个选择:

include / require include / require

You can use the keywords include or require to tell PHP to basically run the contents of another PHP file in the current file, like so:您可以使用关键字includerequire告诉 PHP 基本上运行当前文件中另一个 PHP 文件的内容,如下所示:

<?php

$foo = "bar";

include "othercode.php"; //or alternatively: require "othercode.php";

echo "$foo + $variableinothercode";
?>

The difference between include and require is that require will throw a critical error if the file could not be found, while include will only throw a warning. includerequire的区别在于,如果找不到文件, require会抛出严重错误,而include只会抛出警告。


iFrame框架

I wouldn't recommend this option;我不会推荐这个选项; however it is an option so I'll include it anyway;但是这一个选项,所以无论如何我都会包含它;

You could simply replace the <div> tags with an <iframe> with it's src attribute set to the location of the file, like so:您可以简单地将<div>标签替换为<iframe>并将其src属性设置为文件的位置,如下所示:

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

Copy/cut the code into the file将代码复制/剪切到文件中

There's always the option of making the other file redundant by copying or cutting the contents of the file into the new file, however this should only be done if the file is not being included or used anywhere else as it will break those scripts;总是可以选择通过将文件的内容复制或剪切到新文件中来使另一个文件变得多余,但是只有在文件没有被包含或在其他任何地方使用时才应该这样做,因为它会破坏这些脚本; a simple include or require will suffice and be infinitely cleaner.一个简单的includerequire就足够了,并且非常干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM