2010年6月14日星期一

[fw-db] Need help REGARDING ZEND_DB MAX(ID)

public function getMaxValue($table,$column) {


$this->_name=$table;
$select = $this->select();
//->from($table, array(new Zend_Db_Expr('max('.$column.')')));

$select->from($table, $column);
// ->from($this->_name,$column);

// ->from($this->_name,"TO_CHAR($COL,'DD/MM/YYYY HH:MI:SS AM') $COL")
// ->where("$where");
//
// $select->order('order');

$results = $this->fetchAll($select);


foreach($results as $row) {
$result = $row["$column"];

}

return $result;

} $catagory = new Model_Documents_Griddyview();

$table= 'ARC_DOCUMENT';
$column='INBOX_NUMBER';

$result = $catagory->getMaxValue($table,$column);
$result+=1;

$innumber = new Zend_Form_Element_Text('INBOX_NUMBER');
$innumber->setLabel($inboxno)
->setRequired(false)
->setValue("$result")
->removeDecorator('Errors')
->removeDecorator('Label')
->setAttrib('disable','disable');
Hi,

i am fairly new to ZEND and PHP...so it takes  me hell of a time searching for small issues...

the thing im facing problem is ZEND_DB....i find making queries in ZEND complicated...is there a way to simply make a query as a STRING and then execute it? like....

$query = "SELECT bla from bla bla where bla bla bla";
$connection(host,dbname....);

then execute->($query, $connection);

??????????????????????


im looking for MAX(columnName) ... in ORACLE it is easy to use it by a simple

select NVL(MAX(INBOX_NUMBER),0)+1 MAXINNUM FROM ARC_DOCUMENT


now i want to use this query in ZEND which is taking all day for me...

this is the query i came up with

$column = 'INBOX_NUMBER';

$this->_name=$table;
            $select = $this->select()
            ->from($table, array(new Zend_Db_Expr('max('.$column.')
')));

            $results = $this->fetchAll($select);
            return $results;



and this was its result

Message: Specified column "INBOX_NUMBER" is not in the row


but the table ARC_DOCUMENT has the column named INBOX_NUMBER..where as INBOX_NUMBER is not the PRIMARY KEY of the table ARC_DOCUMENT...and i don't want to put a sequence on it or anything..


where am i going wrong????

please find with this email, the code for my model function and form part where i am using it

please help...before i start hating ZEND or get killed by my manager :-Z


--
Regards,
YD

没有评论: