gpt4 book ai didi

php - Smarty foreach mysql 问题

转载 作者:行者123 更新时间:2023-11-29 22:38:14 24 4
gpt4 key购买 nike

smarty 中的 foreach 遇到一些问题。

php

$rows4 = array(); 
$result4 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5");
while($row4 = mysql_fetch_assoc($result4)) {
$rows4[] = $row4;
}

$rows45 = array();
$result45 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5 OFFSET 1");
while($row45 = mysql_fetch_assoc($result45)) {
$rows45[] = $row45;
}

/** assign variable */

$smarty->assign('rows4', $rows4);
$smarty->assign('rows45', $rows45);

tpl

{foreach $rows4 as $row4} 
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$row45.count}</center></td>
</tr>
{/foreach}

但是我现在如何在这个 foreach 中分配第二个查询,这不起作用:

{foreach $rows4 as $row4 || $rows45 as $row45} 
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$row45.count}</center></td>
</tr>
{/foreach}

最佳答案

试试这个:

$rows445 = array();
$result4 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5");
while ($row4 = mysql_fetch_assoc($result4)) {
$rows445[]['row4'] = $row4;
}

$result45 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5 OFFSET 1");
while ($row45 = mysql_fetch_assoc($result45)) {
$rows445[]['row45'] = $row45;
}

/** assign variable */
$smarty - > assign('rows445', $rows445);

关于php - Smarty foreach mysql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29467631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com