如何在脚本中将文件 php 添加到 tpl
how to add file php to tpl in scripts
我想把php文件放到tpl
以下代码
<?php
$servername = "localhost";
$username = "1_1";
$password = "1=~Eh]V";
$dbname = "11_11";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT domain FROM insights_base WHERE domain_1 = current_date() ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Domain Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["domain"]. " </td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}`enter code here`
$conn->close();
?>
文件路径
require_once $current_dir 。 '/app.config.php';
require_once $current_dir 。 '/lib/smarty/Smarty.class.php';
require_once $current_dir 。 '/lib/classes/Database.singleton.php';
require_once $current_dir 。 '/function_core.php';
index.php:
<?php
require 'libs/Smarty.class.php';
$servername = "localhost";
$username = "1_1";
$password = "1=~Eh]V";
$dbname = "11_11";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT domain FROM insights_base WHERE domain_1 = current_date() ";
$result = $conn->query($sql);
$data = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$data[] = $row;
}
}
$conn->close();
$smarty = new Smarty;
$smarty->assign('data', $data);
$smarty->display('index.tpl');
index.tpl:
<table>
<tr><th>Domain Name</th></tr>
{foreach from=$data key=k item=i}
<tr>
<td>{$i.domain}</td>
</tr>
{/foreach}
</table>
您可以找到更多信息和示例 here。
我想把php文件放到tpl 以下代码
<?php
$servername = "localhost";
$username = "1_1";
$password = "1=~Eh]V";
$dbname = "11_11";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT domain FROM insights_base WHERE domain_1 = current_date() ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Domain Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["domain"]. " </td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}`enter code here`
$conn->close();
?>
文件路径
require_once $current_dir 。 '/app.config.php';
require_once $current_dir 。 '/lib/smarty/Smarty.class.php';
require_once $current_dir 。 '/lib/classes/Database.singleton.php';
require_once $current_dir 。 '/function_core.php';
index.php:
<?php
require 'libs/Smarty.class.php';
$servername = "localhost";
$username = "1_1";
$password = "1=~Eh]V";
$dbname = "11_11";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT domain FROM insights_base WHERE domain_1 = current_date() ";
$result = $conn->query($sql);
$data = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$data[] = $row;
}
}
$conn->close();
$smarty = new Smarty;
$smarty->assign('data', $data);
$smarty->display('index.tpl');
index.tpl:
<table>
<tr><th>Domain Name</th></tr>
{foreach from=$data key=k item=i}
<tr>
<td>{$i.domain}</td>
</tr>
{/foreach}
</table>
您可以找到更多信息和示例 here。