php 获取类方法里面的内容怎么查看变量是否获得内容

class Search_goods {
//获取商品列表
public function search_goods_list($bn,$price,$cost,$weight,$name,$cat_name,$store,$unit,$brand){
$sql="select a.bn,a.price,a.cost,a.weight,a.name,b.cat_name,a.store,a.unit,a.brand from sdb_goods a,sdb_goods_cat b where a.cat_id=b.cat_id";
$res=mysql_query($sql);
$g_res=mysql_fetch_array($res);
while($g_res){
$g_res['bn']=$this->search_goods_list($bn);
$g_res['price']=$this->search_goods_list($price);
$g_res['cost']=$this->search_goods_list($cost);
$g_res['weight']=$this->search_goods_list($weight);
$g_res['name']=$this->search_goods_list($name);
$g_res['cat_name']=$this->search_goods_list($store);
$g_res['store']=$this->search_goods_list($store);
$g_res['unit']=$this->search_goods_list($unit);
$g_res['brand']=$this->search_goods_list($brand);
}
}
}

第1个回答  2012-09-18
class Search_goods {
//获取商品列表
public function search_goods_list($bn,$price,$cost,$weight,$name,$cat_name,$store,$unit,$brand){
$sql="select a.bn,a.price,a.cost,a.weight,a.name,b.cat_name,a.store,a.unit,a.brand from sdb_goods a,sdb_goods_cat b where a.cat_id=b.cat_id";
$res=mysql_query($sql);
$g_res=mysql_fetch_array($res);
while($g_res){
$g_res['bn']=$this->search_goods_list($bn);
$g_res['price']=$this->search_goods_list($price);
$g_res['cost']=$this->search_goods_list($cost);
$g_res['weight']=$this->search_goods_list($weight);
$g_res['name']=$this->search_goods_list($name);
$g_res['cat_name']=$this->search_goods_list($store);
$g_res['store']=$this->search_goods_list($store);
$g_res['unit']=$this->search_goods_list($unit);
$g_res['brand']=$this->search_goods_list($brand);
//你直接输出下看看呗

var_dump($g_res);

}
}
}追问

我按你的方法写了,但是还是没有输出内容

追答

那就是说明你根本没进入这个方法
你创建这个类了吗?

追问

我是新手,还在学习中,所以不是很明白,我现在改了代码,你帮我看下对吗?能把数据库查的东西放入方法里面吗

追答

类要先生成才能使用像这样
$goods=new Search_goods();
$goods_list=$goods->search_goods_list($bn,$price,$cost,$weight,$name,$cat_name,$store,$unit,$brand);
只有这样才是整个运行类里面方法的过程
不经过这样是不能运行类里的方法的

本回答被提问者和网友采纳
第2个回答  2012-09-19
如果你只是想看看有没有获得值,用“吃饭我用盆”那哥们的方法就行,输出下看看便知;
如果你是想做个判断,可以
if( isset($g_res['bn']) && $g_res['bn'] != '')
来做判断
第3个回答  2012-09-21
search_goods_list 是类里面的一个方法,在这个方法里面又调用这个方法是递归。这些我们都知道。
问题在于在这个函数里面调用自己时参数个数完全不对,函数没有形参,调用时实参也驴头不对马嘴,这样都不报错??
第4个回答  2015-06-07
使用empty($val),当$val为空字符串,0,空数组的时候会retuan false

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网