CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Output double (http://www.codingforums.com/showthread.php?t=287735)

mh_and 02-16-2013 12:03 PM

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

Fou-Lu 02-16-2013 03:47 PM

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.

mh_and 02-17-2013 09:16 AM

Now that's embarrassing. Really... Love this forums. And I was like researching 3 hours to find why this can happen..

Thanks


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.