CodeIgniter Forums
Duplicate foreach - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Duplicate foreach (/showthread.php?tid=90523)



Duplicate foreach - FlavioNeves - 03-30-2024

Hello everybody!
I've been having a problem for a few days, and I can't solve it.
Can anyone help me?

I have a filter, where I am doing a join, but I am getting duplicate results.

$modelApp = new \App\Models\App();
$menuPai = new \StdClass();
$request->menuPai = $modelApp->select('apps.*, appmenus.menuAdmin submenu')
->join('appmenus', 'appmenus.app_url_admin = apps.urlAdmin', 'left')
->findAll();
return $request;

The Email main menu should appear once, and below it show the Enviar and Criar submenus.

However, the Email main menu is repeating.


[Image: jpwQW3I.png]


RE: Duplicate foreach - InsiteFX - 03-30-2024

You need to show your code if you want help.

show the code for your foreach loops etc.


RE: Duplicate foreach - MMLTech - 03-30-2024

Are you certain you are not prefilling the menu or calling the append method twice somewhere in the code ?


RE: Duplicate foreach - FlavioNeves - 03-31-2024

the code is just what I put above, nothing more. It's a before filter.

in view it looks like this


<aside id="sidebar" class="sidebar">

    <ul class="sidebar-nav" id="sidebar-nav">

      <?php foreach ($menuPai as $menuPai) { ?>
       
        <?= esc($menuPai->menuAdmin); ?> <br>

        <?= esc($menuPai->submenu); ?> <br><br>

      <?php } ?>

    </ul>

  </aside>

[Image: iGMVhlS.png]


RE: Duplicate foreach - InsiteFX - 04-01-2024

Where's your html code for <li> and <dropdown> etc?


RE: Duplicate foreach - FlavioNeves - 04-06-2024

I already managed to solve it, but I didn't relate the tables, it wouldn't work this way.