function edit( $option, $uid ) {
global $database;
$row = new mosHello_world( $database );
echo "<script> alert('".$uid."')</script>";
$row->loadAllKeys( $uid );
HTML_hello_world::edit( $option, $row );
}以上调用 下面的方法 。 其实主要是想实现一个 按指定id查询一条数据的功能
55 但下面看不懂 。
请高手们解释下 下面的方法怎么一步一步实现的 ? 越详细越好啊 ~ 谢谢
function loadAllKeys( $oid=null ) {
$k = $this->_tbl_key;
if ($oid !== null) {
$this->$k = $this->_db->getEscaped($oid);
}
$oid = $this->$k;
if ($oid === null) {
return false;
}
$this->_db->setQuery( "SELECT * FROM $this->_tbl WHERE $this->_tbl_key='$oid'" );
return $this->_db->loadObject( $this );
}
//查找函數
function loadAllKeys( $oid=null ) {
$k = $this->_tbl_key;
//$k置為一個關鍵值
if ($oid !== null) { //傳進來的$oid不為空則處理
$this->$k = $this->_db->getEscaped($oid);
}
$oid = $this->$k; //將上一步處理的值再賦給$oid
if ($oid === null) { //如果為空則返回失敗
return false;
}
$this->_db->setQuery( "SELECT * FROM $this->_tbl WHERE $this->_tbl_key='$oid'" ); //執行查詢
return $this->_db->loadObject( $this ); //返回查詢結果
}
例如:<php? echo $row->press ?> (数据库里该表的字段有 id name press )
这个方法的注释是:
/**
* binds an array/hash to this object
* @param int $oid optional argument, if not specifed then the value of current key is used
* @return any result from the database operation
*/难道是$row 有问题?
这个数据库文件所有的属性都先要定义!