当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to retrieve specific value from zendframework 2.0 database

问题描述:

Hello i have a question about the zend framework. I have a database with a column having values yes and no. I wish to be able to retrieve from that column only yes values.

This is my code but no success:

public function getListi(array $filterBy = array())

{

$id = 'yes';

$select = $this->sql->select();

$select->from(self::TABLE);

$select->columns(['security_maintenance']);

$select->where(array(

'security_maintenance' => $id

));

$statement = $this->sql->prepareStatementForSqlObject($select);

return $statement->execute();

}

view :

<div class="value-self"><?php

foreach ($domainii as $row) {

echo $row['security_maintenance'];

}

?></div>

controller:

public function indexAction()

{

return new ViewModel(array(

'domainii' => $this->getDomainModel()->getListi(),

));

}

The column is called security_maintenance. the above does not work but when i query by id it works but that does not help me as querying by id will not help me get yes values from the security_maintenance column.

网友答案:

Hello i got it working after doing some research into some zend documentation. This is my code:

public function getListii(array $filterBy = array())

{

$select =  $this->sql->select();
$select->from(self::TABLE);
$select->columns(['security_maintenance']);
$select->where->like('security_maintenance', 'yes%');
$statement = $this->sql->prepareStatementForSqlObject($select);
return $statement->execute();

}
网友答案:

You need to specify the columns you want to select.

try adding the below code

$select->columns(['security_maintenance']);
分享给朋友:
您可能感兴趣的文章:
随机阅读: