Php – return values from class php oop

oopPHP

the code is as follow:

Class userinfo {
    function fetchdatabyemail($email) {
        $result=mysql_query(" SELECT * FROM users WHERE email='$email'"); 
        while($row = mysql_fetch_array($result)) {
            $name = $row['name'];
            $num = $row['num'];
            $city = $row['city'];
        }
        $numrows= mysql_num_rows($result);    
    }
}

now to get the info I do this :

$info = new userinfo();
$info->fetchdatabyemail('email@email.com');  
echo $info->city; 

and it doesnt return the info. I think Im doing something wrong any ideas please

Best Answer

do it

public $numrows;
public function fetchDataByEmail($email) {
        $result=mysql_query(" SELECT * FROM users WHERE email='$email'"); 
        while($row = mysql_fetch_assoc($result)) {
        $fetch[] = $row;
        }
        $this->numrows = mysql_num_rows($result);  
        return $fetch;  
}

then

$info = new userinfo();
$detail = $info->fetchDataByEmail('email@email.com');  
print_r($detail); // return all result array
$info->numrows; // will return number of rows.