Mostly Ghostly Posted August 19, 2009 Share Posted August 19, 2009 Hello everyone, I'm using a download called "Auto Generating Gallery 3". I've not changed anything important, but I'm getting "Notice: Undefined variable: count in gallery.php on line 148" Line 148 is: $count++; :( Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/ Share on other sites More sharing options...
trq Posted August 19, 2009 Share Posted August 19, 2009 Probably just a poorly coded script. Were going to need to see more code however if you want any help fixing it. Maybe 20 lines prior to that will do. Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901663 Share on other sites More sharing options...
Mostly Ghostly Posted August 19, 2009 Author Share Posted August 19, 2009 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 ''; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901665 Share on other sites More sharing options...
trq Posted August 19, 2009 Share Posted August 19, 2009 Change this.... foreach($files as $file) { $count++; to.... $count = 0; foreach($files as $file) { $count++; Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901666 Share on other sites More sharing options...
Mostly Ghostly Posted August 19, 2009 Author Share Posted August 19, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901670 Share on other sites More sharing options...
Mostly Ghostly Posted August 19, 2009 Author Share Posted August 19, 2009 Well, I thought the problem was solved. Now the images aren't opening in a seperate window, they just load a mile further down the page! Any help would be great! :'( Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901804 Share on other sites More sharing options...
KevinM1 Posted August 19, 2009 Share Posted August 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/170955-undefined-variable-error-count/#findComment-901857 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.