The following non-trivial PHP code is available:

$req = DB::run("SELECT * FROM `license` WHERE `id_user`='" . $this->user['id'] . "' ORDER BY `id` DESC LIMIT " . $this->page . ", " . $this->message); while ($row = $req->fetch(PDO::FETCH_ASSOC)) { $arrayrow[] = $row; $reqs = DB::run("SELECT * FROM `cms_php` WHERE `cms`='" . $row['cms'] . "' ORDER BY `id` ASC"); while ($rows = $reqs->fetch(PDO::FETCH_ASSOC)) { $arrayrows[] = $rows; } } 

I pass it to the template like this:

 SmartySingleton::instance()->assign(array( 'arrayrow' => $arrayrow, 'arrayrows' => $arrayrows )); 

In the template output like this:

 {foreach $arrayrow as $row} <tr> <td>{$row.namecms|esc}</td> <td>{$row.code}</td> <td>{if $row.activation == 1}активирована{else}не активирована{/if}</td> <td> {if $row.price == 0} {foreach $arrayrows as $rows} {if $row.cms == $rows.cms} <span><a href="{$home}/load/{$row.cms}/{$rows.id}">{$rows.name|esc}</a></span> {/if} {/foreach} {else} {foreach $arrayrows as $rows} {if $row.cms == $rows.cms} <span><a href="{$home}/profile/load/{$row.id}/{$rows.id}">{$rows.name|esc}</a></span> {/if} {/foreach} {/if} </td> </tr> {/foreach} 

What is wrong: i.e. values ​​are repeated?

Result

How to display in the template?

  • Имеется следующий не тривиальный PHP код - just the very quite trivial and, in principle, wrong ...... because most likely it is enough to group them by a certain sign ... or to join ... i.e. Only one query ............ and what is the expected output? - Alexey Shimansky
  • It is necessary to display php versions for each license. - vitagame
  • one
    What wildness? What is the use of PDO, if you still push the variables directly into the query? It's easy to write $req = DB::run("SELECT * FROM license WHERE id_user=? ORDER BY id DESC LIMIT ?, ?", [$this->user['id'],$this->page, $this->message]); - Ipatiev
  • Ipatiev, thanks for the comment, but this does not solve the problem. - vitagame
  • Your problem is not in Smarti, but in the results of the query. See what you choose there. - teran

1 answer 1

The easiest way to do this is this:

 {foreach array_slice($arrayrows, 0, ЧИСЛО) as $rows} <span><a href="{$home}/load/{$row.cms}/{$rows.id}">{$rows.name|esc}</‌​a></span> {/foreach} 
  • insert pieces of data preparation in the form of array_slice into templates is not the best solution. - teran