Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts

    Cleaning Up PHP generated HTML

    Here's my problem. I'm using a simple query to generate an unordered list. Everything works great except that the generated html comes out like this:
    Code:
    <ul><a href="01_soc.php?recordID=1">Home</a> <ul></ul><li><a href="01_soc.php?recordID=4">About</a> <ul><a href="01_soc.php?recordID=11">Mission</a> <ul></ul><li><a href="01_soc.php?recordID=12">History</a> <ul></ul></li><li></li></ul></li><li><a href="01_soc.php?recordID=6">Charity</a> <ul></ul></li><li><a href="01_soc.php?recordID=2">Magazine</a> <ul><a href="02_soc.php?recordID=20">2012 Spring Summer</a> <ul></ul><li></li></ul></li><li><a href="02_soc.php?recordID=17">Store</a> <ul></ul></li><li></li></ul>
    I have had success before by adding a \n to the loop but I can't figure out where to put it in this loop to fix the problem.
    PHP Code:
    <?php // Top Nav Querry
        
    $parentid 0// assuming that 0 is the main category.
        
    getTopParent($parentid);
        function 
    getTopParent($parentid) { 
            
    $sql "SELECT * FROM pageTypes, pages 
            WHERE approved = 'y' 
            AND pages.menuPosition = 1
            AND pages.pageType = pageTypes.id 
            AND pages.pageParent = "
    .$parentid."
            ORDER BY menuOrder, pageName ASC"

        
    $run mysql_query($sql);
        
        echo 
    '<ul>';
        while (
    $rec mysql_fetch_assoc($run)) { 
            echo 
    '<li>',
            
    '<a href="',$rec['pageLinkName'],'?recordID='$rec['id'],'">',
             
    $rec['pageName'], '</a>',
            
    ' ' 
            
    getTopParent($rec['id']);
            echo 
    '<li>';
            }
        echo 
    '</ul>';
        }
    ?>
    The \n after the </li> doesn't do it.

    I'd love to generate code that looks like this:
    Code:
    <ul>
       <li>List Item</li>
       <li>List Item</li>
       <li>List Item</li>
    </ul>
    Last edited by rgEffects; 09-13-2013 at 08:17 AM.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    You didn't post your attempt, but a \n is only output by php as a new-line character when it is enclosed by double-quotes - "\n"
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    rgEffects (09-13-2013)

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    It was the double quotes. I was using '\n' instead of "\n".

    Thank you


  •  

    Posting Permissions

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