Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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的分离_Php - Fatal编程技术网

php的分离

php的分离,php,Php,这是一个显示产品详细信息的php文件(使用产品id) 无标题文件 我将html和php分开,并将它们放在两个不同的文件夹中 比如folderA/code.php <?php require 'config/config.php'; ?> //Get all details from the products table for the product selected $sql = "SELECT productid, productsku, p

这是一个显示产品详细信息的php文件(使用产品id)


无标题文件
我将html和php分开,并将它们放在两个不同的文件夹中

比如folderA/code.php

    <?php
    require 'config/config.php'; ?>
    //Get all details from the products table for the product selected 
    $sql = "SELECT productid, productsku, productname, productimage WHERE productid = \"" . $connect->real_escape_string($_GET['id']) . "\" LIMIT 0,1";
    $result = $connect->query($sql);
    $row = $result->fetch_assoc();

    extract($row);
    echo $productname;
    echo '<img src=../lbbosystem/'.$productimage.' width="210" height="240">';
    echo $productname; 
    echo $lbproductsku; 
    ?>

//从products表中获取所选产品的所有详细信息
$sql=“选择productid、productsku、productname、productimage,其中productid=\”。$connect->real\u escape\u字符串($\u GET['id'])。“\”限制0,1”;
$result=$connect->query($sql);
$row=$result->fetch_assoc();
摘录(行);
echo$productname;
回声';
echo$productname;
echo$lbproductsku;
?>
和folderB/productdetails.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

</body>
</html>

无标题文件

我如何让他们一起使用产品id制作显示器?。请提供帮助。

如果您正在寻找模板系统,您应该了解Smarty()

代码看起来像这样

require 'config/config.php'; 
require 'smarty/libs/Smarty.class.php';
//Get all details from the products table for the product selected 
$sql = "SELECT productid, productsku, productname, productimage WHERE productid = \"" . $connect->real_escape_string($_GET['id']) . "\" LIMIT 0,1";
$result = $connect->query($sql);
$row = $result->fetch_assoc();

extract($row);
$smarty = new Smarty();
$smarty->assign("productname", $productname);
$smarty->assign("productimage", $productimage);
$smarty->assign("lbproductsku", $lbproductsku); 
$smarty->display("template.tpl");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
    {$productname}<br />
    <img src="{$productimage}" />
    {$lbproductsku}
</body>
</html>
template.tpl就是这样的

require 'config/config.php'; 
require 'smarty/libs/Smarty.class.php';
//Get all details from the products table for the product selected 
$sql = "SELECT productid, productsku, productname, productimage WHERE productid = \"" . $connect->real_escape_string($_GET['id']) . "\" LIMIT 0,1";
$result = $connect->query($sql);
$row = $result->fetch_assoc();

extract($row);
$smarty = new Smarty();
$smarty->assign("productname", $productname);
$smarty->assign("productimage", $productimage);
$smarty->assign("lbproductsku", $lbproductsku); 
$smarty->display("template.tpl");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
    {$productname}<br />
    <img src="{$productimage}" />
    {$lbproductsku}
</body>
</html>

无标题文件
{$productname}
{$lbproductsku}
文件夹层次结构:

root/
  |----index.php
  |----folderA
  |       |----code.php
  |----folderB
  |       |----productdetails.html
Code.php

 <?php
    require 'config/config.php'; ?>
    //Get all details from the products table for the product selected 
    $sql = "SELECT productid, productsku, productname, productimage WHERE productid = \"" . $connect->real_escape_string($_GET['id']) . "\" LIMIT 0,1";
    $result = $connect->query($sql);
    $row = $result->fetch_assoc();

    extract($row);
    echo $productname;
    echo '<img src=../lbbosystem/'.$productimage.' width="210" height="240">';
    echo $productname; 
    echo $lbproductsku; 
    ?>
<?php

ob_start();
include_once("folderA/code.php");
$codes = ob_get_contents();
ob_end_clean();

$html=file_get_contents('folder/productdetails.html');
$html_with_code=str_replace("[content]", $codes, $html);

echo $html_with_code;

?>

//从products表中获取所选产品的所有详细信息
$sql=“选择productid、productsku、productname、productimage,其中productid=\”。$connect->real\u escape\u字符串($\u GET['id'])。“\”限制0,1”;
$result=$connect->query($sql);
$row=$result->fetch_assoc();
摘录(行);
echo$productname;
回声';
echo$productname;
echo$lbproductsku;
?>
Productdetails.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
        [content]
</body>
</html>

无标题文件
[内容]
Index.php

 <?php
    require 'config/config.php'; ?>
    //Get all details from the products table for the product selected 
    $sql = "SELECT productid, productsku, productname, productimage WHERE productid = \"" . $connect->real_escape_string($_GET['id']) . "\" LIMIT 0,1";
    $result = $connect->query($sql);
    $row = $result->fetch_assoc();

    extract($row);
    echo $productname;
    echo '<img src=../lbbosystem/'.$productimage.' width="210" height="240">';
    echo $productname; 
    echo $lbproductsku; 
    ?>
<?php

ob_start();
include_once("folderA/code.php");
$codes = ob_get_contents();
ob_end_clean();

$html=file_get_contents('folder/productdetails.html');
$html_with_code=str_replace("[content]", $codes, $html);

echo $html_with_code;

?>


?或者你是在找模板系统?@castis,不,我不是在找模板系统。PHPTAL没有那么难看,但已经有人说OP不是在找模板系统。看起来不错,让我试试。谢谢,我试用后会回来的。谢谢,效果很好。现在,我可以将php代码与html标记语言分开。index.php将php和html组合在一个页面(productdisplay)上,但如果我有多个页面呢?我刚才回答了你的问题,但这不是组合php和html或拆分的好方法。我推荐MVC系统解决这个问题。祝你好运