Simple Login Form Using PDO .The Output of echos works fine .Enters inside the else case But does not go inside the foreach loop. The output of var_dump gives this .
echo output
1rows SelectedEntered successfull loop
var_dump output
object(PDOStatement)[3] public 'queryString' => string 'select * from tour_login where username='admin' and password='admin' and status=1' (length=81)
  if(isset($_POST['login']))
                {
                    $un=$_POST['un'];
                    $pass=$_POST['pass'];
                    $res=DB::getInstance()->query("select * from tour_login where username='$un' and password='$pass' and status=1");
                    $num_rows = $res->fetchColumn();
                    echo $num_rows."rows Selected";
                    if($num_rows<=0)
                    {   echo "Entered error loop"; 
                        echo "<script>alert('invalid username and password');document.location='index.php';</script>";
                        return false;
                    }
                    else
                    {
                        echo "Entered successfull loop"; 
                            foreach ($res as $row) {
                                echo "Entered successfull for loop"; 
                                        if($row['type']==0)
                        {
                            $_SESSION['admn']=$un;
                            echo "<script>alert('welcome admin...');document.location='adminhome.php';</script>";
                        }
                        else
                        {
                            $_SESSION['usr']=$un;
                            echo "<script>alert('welcome user...');document.location='userhome.php';</script>";
                        }
                            }
                    }
                }
What I am not understanding is why foreach is not working with number of rows showing one.New to Php.I found alternative of using mysql_num_rows() in pdo in this StackOVerflow Question https://stackoverflow.com/questions/11305230/alternative-for-mysql-num-rows-using-pdo