Here are a couple of suggestions for this snippet above:
- Foreach loops are built like this:
foreach ($array as $individual_variable) {
do_something($individual_variable);
}
- A function doesn't need to be defined inside a loop. I would move it to the bottom of the script. The first line of your function is:
function FileSizeConvert($bytes) { //moved up from the line below; I don't like the author's style manual, although it is common and acceptable.
The last two lines of the function are:
return $result;
}
So, the first thing I would do is move this function to the very top of the script (it could, optionally, be moved to the very bottom).
This would leave this:
$sQL = "SELECT userID, SUM(fileSize) FROM file WHERE userId = ".$Auth->id." ";
$new = $db->getRows($sQL);
foreach($new[1] as $bytes);
echo $result;
print_r($new);
As you can see, the loop isn't constructed properly (not constructed at all, really, as bradgrafelman points out).
I don't know the content/structure that $db->getRows() returns, but I'm guessing what you want is something like this:
$sQL = "SELECT userID, SUM(fileSize) FROM file WHERE userId = ".$Auth->id." ";
$new = $db->getRows($sQL);
foreach($new as $data_array) {
echo "User: ".$data_array[0]."<br>";
echo "Space Used: ".FileSizeConvert($data_array[1]);
echo "<br>";
}
//debugging use only
//print_r($new);
HTH,