Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

while else statement? PHP

Tags:

php

So I have a validation in null values using while statement the code is

while (!$rs->EOF){ 
    echo "<tr><td>".$rs->Fields("Branch")."</td>";
    $rs->movenext();
}
$rs->Close();   

?>

What I wanted to achieve is to have an "else" statement though I know its not possible using the where statement. Which one is equivalent of it in where statement?

while (!$rs->EOF){ 
    echo "<tr><td>".$rs->Fields("Branch")."</td>";
    $rs->movenext();
}
if(!$rs->EOF)
{
    echo "<tr><td> Branch is missing</td>";
}
$rs->Close();   

?>

I tried using "if" I didn't get any errors though it didn't print what I wanted to print

like image 780
Yinks Avatar asked Feb 19 '13 07:02

Yinks


1 Answers

While-Else does not exists in php.

You could use:

if ($rs->EOF) {
    echo "<tr><td> Branch is missing</td>";
} else {
    while (!$rs->EOF){ 
        echo "<tr><td>".$rs->Fields("Branch")."</td>";
        $rs->movenext();
    }
}
$rs->Close(); 
like image 69
Tieme Avatar answered Oct 18 '22 17:10

Tieme