Page 1 of 1

While loop in a while loop [SOLVED]

Posted: Fri Feb 26, 2010 4:09 pm
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