Jump to content

[SOLVED] Maintaining a counter variable!


dai.hop

Recommended Posts

Hello all,

 

Everytime I call this function the $counter variable goes back to zero. I would like to be able to call it three times and have the counter not reset back to zero.

 

Here is my code:

 

function create_items($orientation)
{
if (isset($counter))
{

} else
{
	$counter = 0;
}

# specify directory to be processed
$path = $_ENV['DOCUMENT_ROOT'] . '../../../images/ebay/canvas_xpress/products/';

# open the directory and save results
$directory = opendir($path);

# table start
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#EDEDED">';

# output rows
while ($file = readdir($directory)) 
{
	# exclude the first two file entries
	if ($file == '.' || $file == '..')
	{

	} else
	{
		# acquire and output the thumbnail file
		$parts = explode("-", $file);
		$filename = $parts[0];
		$thumbnail = $parts[1];
		if ($thumbnail == 'thumbnail.jpg')
		{
			# acquire image size and set 
			list($width, $height) = getimagesize($path . $file);

			# determine image dimensions and set display variables accordingly
			switch ($orientation) 
			{
				case 'landscape':
					if ($height < $width)
					{
						begin_ouput('width="45" height="30"', $counter, $filename, $path, $file);
						$counter = $counter + 1;
					}
				break;

				case 'portrait':
					if ($height > $width)
					{
						begin_ouput('width="20" height="30"', $counter, $filename, $path, $file);
						$counter = $counter + 1;
					}
				break;

				case 'square':
					if ($height == $width)
					{
						begin_ouput('width="30" height="30"', $counter, $filename, $path, $file);
						$counter = $counter + 1;
					}
				break;
			}
		}
	}
}

# table end
echo '</table>';
}

function begin_ouput($attributes, $counter, $filename, $path, $file)
{
# 
$filename_shortened = strlen($filename) > 25 ? substr($filename, 0, 25) . '...' : $filename;

# begin output
echo '<tr class="table_row_hover" onclick="document.form.image_select[' . $counter . '].checked = true;"><td>' . '<input id="image_select" name="image_select" type="radio" value="' . $filename . '" />' . '</td><td>' . '<a href="' . $path . $filename . '-closeup.jpg' . '" target="_blank"><img src="' . $path . $file . '" ' . $attributes . ' hspace="5" vspace="8" border="0" class="border_grey_light" alt="Click for larger version"></img></a>' . '</td><td>' . $filename_shortened . '</td></tr>';
}

I'm sure theres a way to beat this but I just can't seem to come up with the answer!

 

Thanks for looking!

 

dai.hop

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.