ueon Posted March 15, 2009 Share Posted March 15, 2009 Basically, I'm using $num_file to return the number of files in a directory, but they're just building up. (as you can see in the source code of http://sunient.ca/charmsky/mjackets.php?page=1). The problem is in the last part of the code. <?php function num_files($dir, $recursive=false, $counter=0) { static $counter; if(is_dir($dir)) { if($dh = opendir($dir)) { while(($file = readdir($dh)) !== false) { if($file != "." && $file != "..") { $counter = (is_dir($dir."/".$file)) ? num_files($dir."/".$file, $recursive, $counter) : $counter+1; } } closedir($dh); } } return $counter; } /* $con = mysql_connect("localhost", "", ""); if (!$con) { die("Could not connect: ' . mysql_error())"; } mysql_select_db("db" , $con); $total = mysql_query("SELECT * FROM total"); //100 */ $total = 8; $count_thumb = 1; $count_group = 1; $div_top = 300; $div_left = 200; $max = 20; $totalpages = $total / $max; $page = $_GET['page']; if(empty($page) || $page == 0) { $count_thumb = 1; $count_group = 1; } if ($page != 1 || $page != 0) { $count_thumb = (($page - 1) * 20) + 1; $count_group = (($page - 1) * 20) + 1; } //positions the thumbnails while ($count_thumb <= $total) { echo "<div style='position: absolute; top: ".$div_top."px; left: ".$div_left."px;'>\n"; echo "<a href='products/men/jackets/detail/".$count_thumb."/1.jpg' rel='lightbox[".$count_thumb."]'><img src='products/men/jackets/thumb/".$count_thumb.".jpg' \></a>\n"; echo "</div>\n"; $div_left = $div_left + 150; if ($div_left == 800) { $div_left = $div_left - 600; $div_top = $div_top + 150; echo "<BR \>\n"; } $count_thumb = $count_thumb + 1; } while ($count_group <= $total) { $file_count = 2; $num_file = num_files("products/men/jackets/detail/$count_group"); while ($file_count <= $num_file) { echo "<a href='products/men/jackets/detail/".$count_group."/".$file_count.".jpg' rel='lightbox[".$count_group."]'></a>\n"; $file_count = $file_count + 1; } $count_group = $count_group + 1; } ?> Link to comment https://forums.phpfreaks.com/topic/149551-cant-clear-variable/ Share on other sites More sharing options...
imperium2335 Posted March 16, 2009 Share Posted March 16, 2009 I clear my variables like this: $var = NULL ; or maybe you can do this: if($var > 0) { $var = 0 ; } but im still a noob. Link to comment https://forums.phpfreaks.com/topic/149551-cant-clear-variable/#findComment-785666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.