简体   繁体   中英

Zend - Selecting a specific field

I'm trying to query a database to find the results of one specific field in a table. The following code, from all the reserach I've done, should return only the 'id_maquina' field but it's actually returning all fields.

$hist_select=$historico->select()
    ->setIntegrityCheck(false)
    ->from(array('t1'=>'maquina_cafe'),array('t1.id_maquina'))
    ->joinLeft(array('t2'=>'maquinas'),'t1.id_maquina=t2.ID')
    ->where('t1.username = ?',$identity);

I added the *array('t1.id_maquina')* to the from method to specify that as the field I want as instructed in a post here on stackoverflow but it's not working. Anyone has any thoughts on what is wrong with this?

Which Zend version do you use?

You select all Columns form the joined table, because '*' (all columns) is default for the join.

Try:

$hist_select=$historico->select()
                      ->setIntegrityCheck(false)
                      ->from(array('t1'=>'maquina_cafe'),array('t1.id_maquina'))
                      ->joinLeft(array('t2'=>'maquinas'),'t1.id_maquina=t2.ID', array())
                      ->where('t1.username = ?',$identity);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM