SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Slightly complex WHILE Loop issue...

    Hi,

    I'm having some issues with a while loop If anyone can help, I'd be over-the-moon.

    I have a category table:
    id | name
    0 | home
    1 | contact

    and pages table:

    id | name | file_name | cat
    0 | home page | index.php | 0
    1 | get in touch | get-in-touch.php | 1
    2 | guestbook | guestbook.php | 1
    3 | feedback | feedback.php | 1


    Now my idea is to use a while loop to display all the pages in my database like the following:

    HTML Code:
    <li id="home"> <!-- category name for the element id -->
    				<a href="">home</a> <!-- category name for the anchor text -->
    				<div class="callout" id="hometab"> <!-- category name before tab in id -->
    				
    					<ul>	
    						<li><a href="#">home page</a></li><!-- page name for anchor text -->			
    					</ul>
    
    				</div>
    </li>
    
    <li id="contact">
    				<a href="">contact</a>
    				<div class="callout" id="contacttab">
    				
    					<ul>	
    						<li><a href="#">get in touch</a></li>			
    <li><a href="#">guestbook</a></li>		
    <li><a href="#">feedback</a></li>		
    					</ul>
    
    				</div>
    </li>
    
    .........etc....................
    But I'm a little unsure where to start.


    Many thanks for any pointers, reeeeeally appreciate any help with this.

    I've been racking my brains for hours now.






    P.S.

    Probably anything but helpful but I did try the following earlier, but didn't get the right result:


    PHP Code:
    <?

            
    require_once('connect.php');

            
    $sql "SELECT pages.name, pages.file_name, pages.cat, category.id, category.name FROM pages INNER JOIN category ON category.id = pages.cat";

            
    $res mysql_query($sql);
            while (
    $row mysql_fetch_array($res)) {

              if (empty(
    $last) || $last != $row['name']) {          

                echo 
    '<li id="' $row['4'] . '">
                    <a href="/' 
    $row['4'] . '">' $row['4'] . '</a>
                    <a class="tab" href="/' 
    $row['4'] . '"></a>
                    <div class="callout" id="' 
    $row['4'] . 'tab">';

                    
    $last $row['name'];
                    
                        echo 
    '<ul>';

            }                    
                        echo 
    '<li>' $row['1'] . '</li>';
                            
            if (empty(
    $last) || $last != $row['name']) {  
                
                        echo 
    '</ul>
                    </div>

                </li>'
    ;

            }

            }

            
    ?>
    Last edited by invision2; Apr 10, 2009 at 13:55.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •