Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/07/2013, 21:10
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Respuesta: Problema con 2 foreach anidados (solo me devuelve 1 registro)

Amigo @ricky0123456: veo le molesto que no lo segui ayudando...... listo... lo primero separe bien MODELO - VISTA - CONTROLADOR o al menos siga su framework

Yo escribiria un metodo como el siguiente para recuperar las categorias del catalogo por Id

Código PHP:
<?php
        
// en el MODELO

        
public function getCategoriaFromCatalogo($id ,$where=null)
        {      
        
          
$this->db->where('id_categoria',$id);     
                  
          
          if (!empty(
$where))
          {
            if (
is_array($where)){
          
              foreach (
$where as $key => $value){
                
$this->db->where($key,$value);
               }                    
               
            }else{
               
$this->db->where($where);
            }            
               
          };            
            
          
$query $this->db->get('catalogo');    
          
          if (
$query->num_rows() > 0)
          {
             
$row $query->row();
             return 
$row->id_categoria;
          }else{
            return 
null;
          }
        }
Para buscar haria algo asi:

Código PHP:
$this->categoria_modelo->getCategoriaFromCatalog($id); 
ó

Código PHP:
$this->categoria_modelo->getCategoriaFromCatalog($id,$array_condiciones); 
Las condiciones estan como array asociativo:

Cita:
array('precio >'=>50000, 'color'='rojo');
__________________
Salu2!