Jump to content

Undefined Variable Error - $count++;


Mostly Ghostly

Recommended Posts

I thought I'd posted it all! My mistake!

 

This is ALL the PHP.

 

        <?php

	/* settings */
	$image_dir = 'gallery/';
	$per_column = 6;


	/* step one:  read directory, make array of files */
	if ($handle = opendir($image_dir)) {
		while (false !== ($file = readdir($handle))) 
		{
			if ($file != '.' && $file != '..') 
			{
				if(strstr($file,'-thumb'))
				{
					$files[] = $file;
				}
			}
		}
		closedir($handle);
	}

	/* step two: loop through, format gallery */
	if(count($file))
	{
		foreach($files as $file)
		{
			$count++;
			echo '<a class="photo-link" rel="one-big-group" target="_blank" href="',$image_dir,str_replace('-thumb','',$file),'"><img src="',$image_dir,$file,'" target="_blank" width="100" height="100" /></a>';
			if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
		}
	}
	else
	{
		echo '';
	}

?>

You are a legend!

 

Thank you! Worked perfectly without fuss!

 

Can I ask how you knew that? Is it simple?

 

I want to learn PHP, but I'm really stupid - I promise to try though!

 

Thanks, once again, fantastic person!

 

You can't increment a value that doesn't exist.  Your original $count didn't contain anything.  The function count and your manually created variable $count are two different things.

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.