Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP页面加载到HTML div中_Php_Html_Mysql - Fatal编程技术网

将PHP页面加载到HTML div中

将PHP页面加载到HTML div中,php,html,mysql,Php,Html,Mysql,因此,我目前正在尝试创建我的网站的一部分,以获取一个mySQL表。我编写php来获取数据,创建一个表,并在一个名为display.php的单独php文件中打印出该表。现在我正试图将它加载到html页面上的一个div中,但由于某些原因,它无法工作。我使用的是XAMPP,php在我的登录页面工作时起作用。代码如下: HTML:(我尝试了include和require) PHP:(如果我只运行PHP页面,它将创建表) 只需将php放入函数中即可。然后你可以这样做: <html> &l

因此,我目前正在尝试创建我的网站的一部分,以获取一个mySQL表。我编写php来获取数据,创建一个表,并在一个名为
display.php
的单独php文件中打印出该表。现在我正试图将它加载到html页面上的一个div中,但由于某些原因,它无法工作。我使用的是XAMPP,php在我的登录页面工作时起作用。代码如下:

HTML:(我尝试了include和require)


PHP:(如果我只运行PHP页面,它将创建表)


只需将php放入函数中即可。然后你可以这样做:

<html> 
<body>
<?php require_once('display.php'); ?>
<div id="display" class="myCustom1">
<?php render(); ?>
</div>
</body>
</html>


<?php
function render() 
{
     //YOUR PHP CODE
}
?>

如果要在html文件中使用
标记,请将包含以下代码的文件的扩展名从
.html
更改为
.php
,这样您就可以使用include函数了

<html>
<body>
    <div id="display" class="myCustom1">
       <?php require('display.php'); ?>
    </div>

    <div id="display" class="myCustom1">
        <?php include("display.php"); ?>
    </div>
</body>
</html> 

还要确保包含路径正确。
希望有帮助

显示应为刀片模板

@include('display') 

给出显示模板的路径

html文件的名称,是html文件还是php文件?还要检查include路径您遇到了什么错误?尝试启用PHP错误报告..注意:没有理由使用像
“$servername”这样的东西
什么时候
$servername
可以。@Poria我的html文件名为index.html,我的php显示。php@Sid如何启用错误报告?因此没有办法将两个文件分开?也只是尝试了一下,然后直接在
$result=mysqli\u query($connect,“SELECT*FROM data1enter”)之后输出代码非常感谢您的帮助!我不知道该文件必须保存为.php文件。它现在工作得很好!
<html>
<body>
    <div id="display" class="myCustom1">
       <?php require('display.php'); ?>
    </div>

    <div id="display" class="myCustom1">
        <?php include("display.php"); ?>
    </div>
</body>
</html> 
@include('display')