While loop in a while loop [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

While loop in a while loop [SOLVED]

Post by lshaw »

Hello,

[EDIT]: This randomly started working - sorry

For a navigation bar I need to put a while loop in another while loop, but the second loop stops the first one before it has looped through everything. I will post my code below and hope you have time to read it. Is there a way to continue the loop?

Code: Select all

 
<?php
                    $count=0;
                    $query=mysql_query("SELECT * FROM link_top_menu");
                    while($array=mysql_fetch_array($query))
                        {
                        if($array['url_or_top_menu']==1) //if it is a link
                            {
                            $url=$array['url'];
                            $text=$array['text'];
                            echo "<li><a href='$url'>$text</a></li>";
                        }
                        else if($array['url_or_top_menu']==0) //if it is a top menu item
                            {
                            $count++;
                            $text=$array['text'];
                            $menu="menu".$count;
                            echo "<li onclick=".'"'."showmenu('$menu')".'"'."><a href='#'>$text</a></li>";
                            $id=$array['id'];
                            $query2=mysql_query("SELECT * FROM link_menu_items WHERE parent=$id");
                            $rows=mysql_num_rows($query2);
                            if($rows>0)
                                {
                                echo "<ul class='menu' id='$menu'>";
                            while($array2=mysql_fetch_array($query))
                                {
                                $text=$array2['text'];
                                $url=$array2['url'];
                                echo "<li><a href='$url'>$text</a></li>";
                            }
                            echo "</ul>";
                                }
                        }
                    }
 
Thanks for your help,

Lewis
Post Reply