I have a recipe website and when a contributor cancels his/her account, I want to keep their recipes and display them as the recipes of an anonymous user. If I do an inner join on users.id = recipes.user_id then the recipe name of the deleted user doesn’t show up and that could be used as a solution however I would prefer to keep the recipes and just display them as from anonymous. I tried various redundant versions of !isset() and empty() which didn’t work. In order to find a solution, I started with the simple process of showing the name “anonymous” for all recipe user_ids equal to one and recipe category_id equal to one. There is only one recipe with both category_id and recipe user_id equal to one however my code printed out all of the user ids equal to one and not just the one with category id equal to one.
foreach ($users as $user):
if ($user->id == $recipe->user_id){
echo $this->Html->link($user->contributor, ['controller' => 'bios', 'action' => 'view', $recipe->user_id]);
} elseif ( $recipe->user_id == '1' && $recipe->category_id == '1' ) {
echo "Anonymous";
}
endforeach; //users