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);
}
}
}
//获取商品列表
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);
只有这样才是整个运行类里面方法的过程
不经过这样是不能运行类里的方法的
如果你是想做个判断,可以
if( isset($g_res['bn']) && $g_res['bn'] != '')
来做判断
问题在于在这个函数里面调用自己时参数个数完全不对,函数没有形参,调用时实参也驴头不对马嘴,这样都不报错??