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 己经是一个数组来的了。 怎么让字符串不停的变动呀? 奇怪问题 页面不显示 但html代码都已经下载下来了 一个登录的问题 求在PHP里面实现一个sql语句: 各位武林高手!小弟想做一个商品的二级分类!可是能力有限啊!急求答案!!帮帮忙!!! 怎样防止截取摘要时将img标签截断? php图片上写汉字的问题,急~~~~~ session以数据库方式存在的接口程序 哪种PHP的编程格式比较科学? 这段PHP的代码能翻译成nodejs的express框架吗? __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['字段名称'];