你好我有这个代码的数组到字符串转换错误:
index.php:
代码:
$hoArr = array(1,2,3);
foreach ($hoArr as $hid) {
$mysqli = mysqli_connect("localhost", "root", "", "zabbixtest");
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT errors_from FROM hosts WHERE hostid = '$hid'";
$re = mysqli_query($mysqli, $sql);
while ($row = mysqli_fetch_assoc($re)) {
$query_times[] = $row['errors_from'];
}
mysqli_free_result($re);
mysqli_close($mysqli);
}
$smarty->assign('query_times',$query_times);
和index.tpl:
代码:
<p>{$query_times}</p>
我不知道它有什么问题..
答案 0 :(得分:0)
您尝试使用$smarty->assign
分配数组,但只能指定字符串。
请改用:
$query_string = implode ( "," , $query_times );
$smarty->assign('query_times',$query_string);
答案 1 :(得分:0)
我有一个简单的解决方案:
的index.php:
$query_string = implode ("</td><td>", $query_times );
的index.html:
<table>
<td>{$query_times}</td>
</table>
现在它在表格中:))