Jump to content

Simple I'm sure - can't work it out myself!


Bricktop

Recommended Posts

Hi guys,

 

I have the following code:

 

function menu($location = null)
{
	$sql = mysql_query("SELECT location FROM database ORDER BY location ASC");

	$locations = array();

	$content .= 'menu1[0]=\'<a href="file.php?fct=showall">Show All</a>\'';

	while ($a = mysql_fetch_array($sql))
	{
		$num = 0;
		++$num;

		if (!in_array($a['location'],$locations))
		{

			$content .= 'menu1['.$num.']=\'<a href="file.php?fct=showstuff&location='.$a['location'].'">'.$a['location'].'</a>\'';

			$locations[] = $a['location'];
		}

	}


return $content;
}

 

Basically, it's a menu I've built which takes the locations from a database and lists them.  This code works fine.  However, in this version you can see I am trying to auto increment $num every time a location is output.

 

I cannot get it to work, all locations come out as the same number - 1.

 

What am I doing wrong please?  Each number just needs to output in order everytime a location is listed, e.g 1, 2, 3, 4, 5 etc etc

 

Thanks, hope this makes sense

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.