2009年8月1日星期六

Re: [fw-db] fecthing data with option

What if you try this one :

$where = $choice .'= ?,'. $material;
$select = $searchDatabase->select()->where($where);
$rows = $searchDatabase->fetchAll($select);
$this->view->searchDatabase = $rows;

regards,
Ari


On Aug 1, 2009, at 10:23 PM, Erdal YAZICIOGLU wrote:

Thanks for the help Simone.

But when I run it, it does not recognize the method quoteInto. I am using Zend_Db_Table.

Thanks again

2009/8/1 Simone Cosci <s.cosci@nextidea.it>
Erdal YAZICIOGLU ha scritto:
Hello all

I have data coming from text box and select box.

<select name="choice">
                          <option  label="cg1a" value="MMT_Number">MMT Number</option>
                          <option  label="cg1a" value="BOM">BOM Number</option>
                          <option  label="cg1a" value="CIN">CIN Number</option>
                        </select>

I am trying to fecth result regarding the choice of user.

In the controller

$filter = new Zend_Filter_StripTags();
$material= $filter->filter($this->_request->getPost('material')); //data coming from input text.
$choice = $filter->filter($this->_request->getPost('choice'));//data from select box.

I set the object
$searchDatabase = new Model_DbTable_MMT();
$where = $choice . '=' . $material
$this->view->searchDatabase = $searchDatabase->fetchAll($where);

$searchDatabase = new Model_DbTable_MMT();
// first verify if the col passed really exists
if ( in_array( $choice, $searchDatabase->info( Zend_Db_Table_Abstract::COLS ) ) )
{
    $where  =  $searchDatabase->getAdapter()->quoteInto($choice . '= ?' , $material);
    $select = $searchDatabase->select()->where($where);
    $rows = $searchDatabase->fetchAll($select);
    $this->view->searchDatabase = $rows;
}else throw new Exception('WTF ??');

--
fsockopen
ZF n00b



Bu no success. Everytime I get MySQL synax error.

Exception information:

Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 1


When I check the trace

IndexController.php(34): Zend_Db_Table_Abstract->fetchAll('MMT_Number= ')     

Now as you can see in the trace and said in error message, it is a syntax error. I tired several ways to write where clause but no success. Can you guys please give your advises?


Best Regards

Erdal YAZICIOGLU
System & Network Engineer
Page Europa S.R.L - General Dynamics
www.pageuropa.it
Office - Rome : +39 0650395292
Mobile -Rome : +39 3490787196
Mobile -Istanbul: +90 536 3447989




--

Erdal YAZICIOGLU
System & Network Engineer
Page Europa S.R.L - General Dynamics
www.pageuropa.it
Office - Rome : +39 0650395292
Mobile -Rome : +39 3490787196
Mobile -Istanbul: +90 536 3447989

没有评论: