Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2013, 12:03 PM   PM User | #1
mh_and
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
mh_and is an unknown quantity at this point
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
mh_and is offline   Reply With Quote
Old 02-16-2013, 03:47 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
mh_and (02-17-2013)
Old 02-17-2013, 09:16 AM   PM User | #3
mh_and
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
mh_and is an unknown quantity at this point
Now that's embarrassing. Really... Love this forums. And I was like researching 3 hours to find why this can happen..

Thanks
mh_and is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:46 PM.


Advertisement
Log in to turn off these ads.