I have 9 blocks, and I want sort it by last news added.
I have code:
$projects = Projects::find(['conditions' => 'active = 1', 'order' => 'id DESC']);
$itemsps = [];
foreach($projects as $project) {
if(!$project->{'link_' . $lang. ''}) continue;
$itemsp['title_md'] = $project->title_md;
$itemsp['title_ru'] = $project->title_ru;
$itemsp['link'] = 'http://'.$_SERVER['SERVER_NAME']. '/' . $lang . '/' . $project->{'link_' . $lang. ''};
$category = Categories::findFirst('alias = ' . "'$project->link_md'" . ' OR alias_ru = ' . "'$project->link_ru'");
$lastCat = NewsCategories::find('categories_id = ' . $category->id)->getLast();
if($lastCat === false) continue;
$lastImage = 'uploads/' . $lastCat['news_id'] . '.jpg';
$itemsp['image'] = $lastImage;
$itemsps[] = $itemsp;
}
How I can order by last records of:
$lastCat = NewsCategories::find('categories_id = ' . $category->id)->getLast();
Results in my array:
itemsps
Copyright Notice:Content Author:「Tatata」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48827545/foreach-sort-results-from-database