1

I got a menu I want to make dynamic with joomla (so i can add an article under a certain category, the category being the top menu level, and that article is shown in a dropdown under the category).

This is some of the basic information I used to try something myself.

The query that outputs the correct data:

// Het bedrijf
$bedrijf                = "SELECT * FROM `lb_content` WHERE catid = 26 and state = 1";
$bedrijfcon             = $conn->query($bedrijf);
$bedrijfcr              = array();
while ($bedrijfcr[]     = $bedrijfcon->fetch_array());

26 is the id of the correct id.

This is the html code I want to make dynamic:

<li class="relative f_xs_none m_xs_bottom_5"><a href="javascript:void()" onclick="javascript:goToURL('http://www.website.nl')" class="tr_delay_hover color_light tt_uppercase"><b>Het bedrijf</b></a>
    <!--sub menu-->
    <div class="sub_menu_wrap top_arrow d_xs_none type_2 tr_all_hover clearfix r_corners">
        <ul class="sub_menu">
            <li><a class="color_dark tr_delay_hover" href="home/wie-zijn-wij">Wie zijn wij?</a></li>
            <li><a class="color_dark tr_delay_hover" href="home/onze-showroom">Onze showroom</a></li>
            <li><a class="color_dark tr_delay_hover" href="home/het-bedrijf/de-beste-keus">De beste keus</a></li>
            <li><a class="color_dark tr_delay_hover" href="home/diensten/leveren-producten-voor-doe-het-zelf">Leveren producten voor doe-het-zelf</a></li>
            <li><a class="color_dark tr_delay_hover" href="home/diensten/informatie-voor-aannemers">Informatie voor aannemers</a></li>
            <li><a class="color_dark tr_delay_hover" href="home/diensten/informatie-voor-architecten">Informatie voor architecten</a></li>
        </ul>
    </div>
</li>

How I have it now is that the above query is in another file which is included in this file, so that query is useable.

I then made this code:

<? 

$i = 1;
$arraylist = array();
    foreach($bedrijfcr as $menu1)
    {
        if(!in_array($menu1['id'],$arraylist) && $menu1['id'] != '')
        {
                $arraylist[] = $menu1['id'];

                $menuitem1 = 
                            '<li class="relative f_xs_none m_xs_bottom_5"><a href="http://vanroonenzoon.nl/" class="tr_delay_hover color_light tt_uppercase"><b>'.$menu1['title'].'</b></a>
                            <div class="sub_menu_wrap top_arrow d_xs_none type_2 tr_all_hover clearfix r_corners">
                            <ul class="sub_menu">';

                $sub1 = "SELECT * FROM `lb_content` WHERE catid = 26 order by created DESC";
                $subcon1            = $conn->query($sub1);
                $subcr1             = array();
                while ($subcr1[]    = $subcon1->fetch_array());

        }

        $i++;

        foreach($subcr1 as $submenu1)
        {
            $menuitem1 = '<li><a class="color_dark tr_delay_hover" href="'.GetSubNaam($submenu1['catid']).'/'.$submenu1['alias'].'">'.$submenu1['title'].'</a></li>';
        }

        $menuitem1 = '</ul>
        </div>
        </li>';
    }
    echo = $menuitem1;

?>

It's not giving any errors but also not the correct data. Does anyone know what I am doing wrong?

Thanks in advance.

Thanks for the answers.

This is the output I get now. It loops this part over and over which is not what I want. He loops all of $menuitem1 while I only want it to loop the part in the $subcr1 foreach.

<li class="relative f_xs_none m_xs_bottom_5"><a href="javascript:void()" onclick="javascript:goToURL(http://www.vanroonenzoon.nl)" class="tr_delay_hover color_light tt_uppercase"><b>Wie zijn wij</b></a>
    <div class="sub_menu_wrap top_arrow d_xs_none type_2 tr_all_hover clearfix r_corners">
    <ul class="sub_menu">
    <li><a class="color_dark tr_delay_hover" href="/"></a></li></ul>
    </div>
</li>
2
  • What is the result you are getting? Commented Nov 3, 2015 at 13:52
  • Nothing. The list is now hardcoded,but if I remove it, the whole menu button just dissapears. I fixed some errors before so the query is correct. Commented Nov 3, 2015 at 13:54

2 Answers 2

2

You're not concatenating your strings. Look:

$menuitem1 = '<li class="relative...';

...

$menuitem1 = '<li><a class="col ...';

...

$menuitem1 = '</ul>...';

Use the .= operator to append a string value.

Sign up to request clarification or add additional context in comments.

4 Comments

Yeah you're right. At least it shows the correct data now :) Only not in the correct css. It outputs the data as top level menu items, not as dropdownitems. It's as if it's looping the top level menu item (the category instead of the articles). As if $menu1 is being looped, but I want $submenu1 to be looping.
My guess is your SQL is not correct. SELECT * FROM lb_content WHERE catid = 26 order by created DESC ... how do you know which parent menu item these submenus should be under? Wouldn't this SQL include the parent menu item too (catid = 26)?
Yeah probably.. But parent_id is only for categories. Articles use catid which 'connects' to the right id of the parent category. And I don't want to output any categories, just the articles under a certain category (category with id 26)
Your SQL for the top-level menu items is SELECT * FROM lb_content WHERE catid = 26 and state = 1, which only slightly differs from your sub-menu SQL (state = 1). You should be restricting this read in some way to not bring in sub-menu items, or else restricting your sub-menu read to not bring in top-level menu items.
1
  <? 
    menuitem1 = "";
    $i = 1;
    $arraylist = array();
        foreach($bedrijfcr as $menu1)
        {
            if(!in_array($menu1['id'],$arraylist) && $menu1['id'] != '')
            {
                    $arraylist[] = $menu1['id'];

                    $menuitem1 .= 
                                '<li class="relative f_xs_none m_xs_bottom_5"><a href="http://vanroonenzoon.nl/" class="tr_delay_hover color_light tt_uppercase"><b>'.$menu1['title'].'</b></a>
                                <div class="sub_menu_wrap top_arrow d_xs_none type_2 tr_all_hover clearfix r_corners">
                                <ul class="sub_menu">';

                    $sub1 = "SELECT * FROM `lb_content` WHERE catid = 26 order by created DESC";
                    $subcon1            = $conn->query($sub1);
                    $subcr1             = array();
                    while ($subcr1[]    = $subcon1->fetch_array());

            }

            $i++;

            foreach($subcr1 as $submenu1)
            {
                $menuitem1 .= '<li><a class="color_dark tr_delay_hover" href="'.GetSubNaam($submenu1['catid']).'/'.$submenu1['alias'].'">'.$submenu1['title'].'</a></li>';
            }

            $menuitem1 .= '</ul>
            </div>
            </li>';
        }
        echo $menuitem1;

    ?>

1 Comment

This shows the articles as the normal menu, not as a dropdown. All other menu items are removed/taken out of the screen too :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.