0

I use Zend 1

CONTROLLER:

    public function insertarAction() {

        $entidades_salud = new Application_Model_DbTable_EntidadesSalud();
        $datos_entidades = $entidades_salud->buscarEntidades();
}

MODEL:

<?php

class Application_Model_DbTable_EntidadesSalud extends Zend_Db_Table_Abstract
{

    protected $_name = 'entidades_salud';
    protected $_primary = 'codigo_entidad_salud';

    public function buscarEntidades() {

        $consulta = $this->select()->from($this->_name);
        $query = $this->fetchAll($consulta)->toArray();
        return $query;

    }


}

PRINT OF CONSULT [print_r($datos_entidades); - in controller]

    Array ( [0] => Array ( [codigo_entidad_salud] => 1 [nombre_entidad] => SANITAS ) 
             [1] => Array ( [codigo_entidad_salud] => 3 [nombre_entidad] => wladfimir )
             [2] => Array ( [codigo_entidad_salud] => 4 [nombre_entidad] => Juli ))
no entraArray ( [controller] => beneficiarios [action] => insertar [module] => default ) 

According to the above result, I require print:

1 SANITAS
3 wladfimir
4 Juli

I think it should work with something like:

        while($row = mysqli_fetch_assoc($datos_entidades)){
                echo $row['codigo_entidad_salud'];
        echo $row['nombre_entidad'];
}

2 Answers 2

2

What you need is foreach loop to iterate through an array.

foreach($datos_entidades as $row){
    echo $row['codigo_entidad_salud'];
    echo $row['nombre_entidad'];
}

Note: The display logic should fall into the view file, you should pass data to view & in view file you need loop to display the records.

Sign up to request clarification or add additional context in comments.

3 Comments

Solved with: for($i=0;$i<count($datos_entidades);$i++) { print $datos_entidades[$i]['codigo_entidad_salud']."<br>"; print $datos_entidades[$i]['nombre_entidad']."<br>"; }
Foreach is better than for to iterate an array still it's upto you.
So I'm doing: pastebin.com/Brp2KDJw but does not work, there is no data i.imgur.com/O3BQ578.png
1

You are converting The results into array, you can do what Rikesh Suggested as,

foreach($datos_entidades as $row){
    echo $row['codigo_entidad_salud'];
    echo $row['nombre_entidad'];
}

And you can pass $datos_entidades to View Script as $this->view->data= $datos_entidades;

and you will be able to use,

foreach($this->data as $row){
    echo $row['codigo_entidad_salud'];
    echo $row['nombre_entidad'];
}

in your view script also,

an alternate approach,

You dont use toArray() in $query = $this->fetchAll($consulta)->toArray();

just use, $query = $this->fetchAll($consulta);

and you will be able access it like following,

foreach($datos_entidades as $row){
    echo $row->codigo_entidad_salud;
    echo $row->nombre_entidad;
}

and will be able to access same way in view script also.

2 Comments

well again as stated,it's more the zendish approach to use foreach then the array. but still your, choice.
In the view I need to do a select (HTML ListBox) pastebin.com/WkSHtbpj But nothing appears if you select Stand no function, other data appears. @dragon-warrior

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.