PHP类中的方法 参数 请指教 本帖最后由 yinfoo8 于 2010-06-19 14:38:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我还写了一种写法 function getInfo1($a){ $this->db->open("SELECT * FROM fke_website"); $result = array(); while ($rs = $this->db->next()) { $result[] = $rs; } return $result[0];}怎么把值返回呢 return 参数 怎么写 请高手指教。。 兄弟,你记住这么一句话,类至少得有Class 你这个不能叫类,你参考一下php手册,里面有几个不错的例子 这哥们估计是学Java的 你也请记住一句话 不是所有情况都必须要用class的 PHP数组可以完成所有数据结构的操作 不是啦。 我只是贴出了其中一个方法 部分代码而已 class website{val ****function getInfo1($a){ $this->db->open("SELECT * FROM fke_website"); $result = array(); while ($rs = $this->db->next()) { $result[] = $rs; } return $result[0];}} class website{ private $db; public $tmp2; protected $tmp3; public __construct() { $this->db = new mysql_db(); // mysql_db是一个操作数据库的类; } function getInfo1($a){ $this->db->open("SELECT * FROM fke_website"); $result = array(); while ($rs = $this->db->next()) { $result[] = $rs; } return $result[0]; // 这里有点问题,如果$result没有0元素就会出错 }}$mydb = new website();$myval = $mydb->getInfo1();echo $myval['字段名称']; 为什么$a这个变量在function getInfo1里面没有出现? return $abc; 你这个 return 己经是一个数组来的了。 【linux安装 libmcrypt 报错】 关于PHP中获取随机密码的疑问 centos 下使用 yum 安装php 5.2.17 无法使用mysql_connect、json_encode等函数 switch匹配问题 关于PHP调用类方法的效率问题 有没有谁做过paypal接口的开发 如取得 指定日期内的 交易的数据 如何把seesion文件保存到当前目录下? 求助PHP5下出错 这个表达式怎么写??? 有关smtp问题!(十万火急,在线给分) __set()函数和__get()函数,为何无法被调用到呢?(几行代码) 关于PHP计算顺序问题
$this->db->open("SELECT * FROM fke_website");
$result = array();
while ($rs = $this->db->next()) {
$result[] = $rs;
}
return $result[0];
}怎么把值返回呢 return 参数 怎么写 请高手指教。。
不是啦。 我只是贴出了其中一个方法 部分代码而已 class website{
val ****
function getInfo1($a){
$this->db->open("SELECT * FROM fke_website");
$result = array();
while ($rs = $this->db->next()) {
$result[] = $rs;
}
return $result[0];
}
}
class website{
private $db;
public $tmp2;
protected $tmp3; public __construct()
{
$this->db = new mysql_db(); // mysql_db是一个操作数据库的类;
} function getInfo1($a){
$this->db->open("SELECT * FROM fke_website");
$result = array();
while ($rs = $this->db->next()) {
$result[] = $rs;
}
return $result[0]; // 这里有点问题,如果$result没有0元素就会出错
}
}$mydb = new website();
$myval = $mydb->getInfo1();
echo $myval['字段名称'];