1

I am trying to do dynamic nav menus for the pages, when admin creates a page, he selects multiple selection for the menus that this page should appears for, I am achieving this through two steps, 1st step adding the selected menus in the database separated by commas using implode(",", $assignNav) "1st step works successfully", 2nd step SELECT query using FIND_IN_SET() to match values in the separated commas.
Result in 2nd step: Just menus without commas "Assigned 1 value" is selected normally, but any pages with commas "assigned multiple values" did not return any output.

2nd Step Query:

                        <?php
                          $query = mysqli_query($dbConnection,"SELECT menu_name FROM navigation_menus WHERE FIND_IN_SET('3',menu_link_id) ");
                          queryConfirm($query);
                          while($row = mysqli_fetch_assoc($query)){
                            $menu_name = escape($row['menu_name']);
                        ?>
                        <h6 class="mb-0 text-sm"><?php echo htmlspecialchars($menu_name); ?></h6>
                        <?php
                          }
                        ?>
wowoffer
  • 13
  • 9
  • How can `FIND_IN_SET(needle, haystack)` find anything in a the haystack if that is a single id? At least I assume that `menu_link_id` will always contain a single id, as the name suggests. – KIKO Software Sep 02 '22 at 08:29
  • In menu_link_id i stored multiple IDs separated by commas like this 1,2,4
    so I'm trying now to output menu_name which contains id 3 from menu_link_id
    – wowoffer Sep 02 '22 at 09:46

0 Answers0