calculations inside of a loop [SOLVED]
Posted: Mon Dec 05, 2005 10:37 pm
I'm thinking that this code keeps adding onto itself inside of the loop, instead of doing a new check on each iteration through the loop. What this code is doing is checking that a person has not gone over their space limit when uploading multiple pictures. I allow 6 MB of space, and during each iteration of the loop, it should check to make sure they have not gone over that limit. However, I'm only at 30% of myspace usage, and even when adding small pictures it tells me I have gone over my limit. Does anyone see any problems?
Code: Select all
for($i=0;$i<10;$i++)
{
if($_FILES['filetoupload']['name'][$i])
{
$totalallowedsize = "6144000";
$subpicsize = mysql_query("SELECT size FROM subpics WHERE username = '$theperson'");
if(mysql_num_rows < 1)
{
$stotal = 0;
} ELSE
{
while($subpicsizearray = mysql_fetch_assoc($subpicsize))
{
$stotal += $subpicsizearray['size'];
}
}
$sql2query = mysql_query("SELECT size FROM albumpictures WHERE username = '$theperson'");
if(mysql_num_rows($sql2query) < 1)
{
$atotal = 0;
} ELSE
{
while($totalalbumsize = mysql_fetch_assoc($sql2query))
{
$atotal += $totalalbumsize['size'];
}
}
$totalsize = $stotal + $atotal;
if($totalsize > $totalallowedsize)
{
echo "<div class=\"error\"><p class=\"main\" align=\"center\">You're over your allowed space limit. Consider deleting some pictures.</p></div><br /></td></tr></table>";
require 'footer.php';
die();
}
}
}