从类php oop返回值 [英] return values from class php oop

查看:59
本文介绍了从类php oop返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

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

推荐答案

做到

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;  
}

然后

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

这篇关于从类php oop返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆