<!-- html-код --> <? if(!empty($array)) foreach ($array as $val){ ?> <!-- html-код --> <? $id = $val['id']; $string = Database->select(" SELECT COUNT(*) FROM `table` WHERE `id` = '$id' "); echo $string; ?> <!-- html-код --> <?}?> <!-- html-код --> I use on the site MVC-model. This is part of the code from View. As you can see, I am confused by the query to the database, because these are tasks of the controller or model.
Question : How to get rid of a query in View, if I need to somehow output the data in a loop depending on $id
PS I am sure that this question was understood somewhere, but I do not even know how to formulate it correctly.
id? will another markup be displayed or what? - Alexey ShimanskySELECЕ count(1) from table group by FIELD? and you will have a sample of counts for each field ..... and further, the result is already passed to the view and cycle we analyze - Alexey ShimanskySELECT DISTINCT id, count(*) FROM table WHERE id IN [Список ID] GROUP BY id- Alex Krassid INselects the totalcount, and the vehicle, as I understand it, for each id you need your own count - Aleksey Shimansky