【发布时间】:2013-12-12 15:50:35
【问题描述】:
使用realestate script 3,它使用smarty 3。
我设法创建了从数据库中获取信息的循环。
<?php
function smarty_function_my_plugin($params,&$smarty)
{
$con=mysqli_connect("localhost","root","","res3");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
$result = mysqli_query($con,"SELECT * FROM res3_listings WHERE listing_type_id=5 ORDER BY views DESC");
while($row = mysqli_fetch_array($result)) {
$title=$row['title_1'];
$price=$row['price'] ;
$id=$row['listing_id'];
$result = mysqli_query($con,"SELECT listing_photo_file FROM res3_listing_photos WHERE listing_photo_id=1");
while($row = mysqli_fetch_array($result)) {
$picture=$row['listing_photo_file'];
}
echo $title. "<br/>".$price."<br/>".$picture;
$smarty->assign('naslov', $title);
echo "<br>";
}
}
mysqli_close($con);
echo '<h1>Test</h1>';
}
?>
所以我将脚本放在插件文件夹中,并在脚本末尾返回 TEST echo 和 3 个变量 $title、$price、$picture。在模板 {my_plugin}
中使用命令但我想访问这些变量,以便可以在 *.tpl 文件中调用它们,例如:{$title}
这样我可以将 HTML 部分放入 .tpl 文件中,然后插入该函数中我需要的变量。
它应该在模板文件上循环 10 个结果;)
【问题讨论】: