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
https://forums.phpfreaks.com/topic/94767-simple-im-sure-cant-work-it-out-myself/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.