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

Thread: Output double

  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Output double

    Hello,

    My thanks in the beginning and please help understand what's the problem. I've started using php and trying to build my very first small website with a few categories and many pages. So I wrote a function:

    Code:
    function getFirstMenu() {
        $query = mysql_query("SELECT `cat_name`, `cat_id` FROM `category`") or die(mysql_error());
        while($menu = mysql_fetch_assoc($query)) {
            echo '<li><a href="?cat='.$menu['cat_id']. '">'.$menu['cat_name'].'<a/></li>';
    
        }
    }
    and I'm using it here

    Code:
    							<ul>
    								<li><a href="index.php" target="_top">Home</a></li>
    								<?php getFirstMenu();?>
    							</ul>
    can someone please tell me why it's outputting 2 links instead of one in a li like this. Second <a> is empty

    Code:
    <li>
    <a href="?cat=1">Name</a>
    <a></a>
    </li>
    Thank you

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Within the while loop add var_dump($menu); and post that. Assuming that the <a/> is a typo just in the forum here, the output you have is consistent with 'cat_name' containing the value Name</a>\n<a>. So lets start there.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    mh_and (02-17-2013)

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Now that's embarrassing. Really... Love this forums. And I was like researching 3 hours to find why this can happen..

    Thanks


  •  

    Posting Permissions

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