Hello Richard,

On 7 Jan 2004 at 21:02, Richard Kurth wrote:

>  I can't seam to get this while loop to work properly. It should create
> a message that has the first two lines and then it will list all the
> domain that meat the criteria. 
> 
> $lines = "The following are web sites that are at 95% usage or more of there web 
> space\n";
> $lines = "Site Name     Used(MB)   Free(MB)   Allowed(MB)  \n";

Hmm, this has nothing to do with your question, but don't you need a concatenation 
operator (.) before the equal sign in the second line of code above?

> $result=mysql_query("SELECT * FROM domplans");
> while($row = mysql_fetch_array($result)){
>   $dom=$row["domname"];
>   $total=$row["quota"];
>   $result1=mysql_query("SELECT * FROM datasubused where domname = '$dom'");
>   $proccess = mysql_fetch_array($result1);
>   $totalused=$proccess["quotaused"];
>   $totalfree=$total - $totalused;
>   $percent = ceil(100*$totalused/$total);
>     If($percent>="95"){

Why is "if" capitalized? Well, it doesn't affect the execution of the code, but it's 
bad 
practice. More importantly, why is the number 95 between quotes? You're comparing 
numbers, not strings. Granted, PHP will convert the string into a number for you, but 
that's bad practice again.

>       $lines = "$dom     $totalused   $totalfree   $total  \n";
>         for( $i=0;$i<count($lines);$i++) {

Aha! Count lines?! What lines do you want counted? $lines is a string, not an array, 
so 
how can you possibly count the number of array elements contained in $lines?

>         $message .=$lines[$i];
>         }
>     }
>   echo $message;
> }

Perhaps what you really want is to create an array $lines with all the strings that 
you 
need and print them at the end. I'm not sure I understand your needs exactly, but 
wouldn't something like the code below work better for you?

/*** CODE START ***/

$dbh = mysql_connect('host', 'username', 'password');
mysql_select_db('db', $dbh);
$lines = "The following are web sites that are at 95% usage or more of there web 
space\n";
$lines .= "Site Name     Used(MB)   Free(MB)   Allowed(MB)  \n";
$result = mysql_query("SELECT * FROM domplans", $dbh);
while( $row = mysql_fetch_array($result) )
{
        $dom=$row["domname"];
        $total=$row["quota"];
        $result1=mysql_query("SELECT * FROM datasubused where domname = 
'$dom'");
        $proccess = mysql_fetch_array($result1);
        $totalused=$proccess["quotaused"];
        $totalfree=$total - $totalused;
        $percent = ceil(100*$totalused/$total);
        $lines = array();
        if($percent >= 95)
        {
                $lines[] = "$dom     $totalused   $totalfree   $total  \n";
        }
}
for( $i=0;$i<count($lines);$i++)
{
        $message .=$lines[$i];
}
echo $message;

/*** CODE END ***/

Hope this helps.

Cheers,

Erik

Reply via email to