Welcome Guest, Not a member yet? Register   Sign In
Make array - Query with JOIN
#2

[eluser]VolkS[/eluser]
SOLVED:

Code:
$query =
  $this->db->select('imagenes.*,imagenes.imagen as nimagen, noticias.id_noticia, noticias.estado,noticias.titulo
    ,noticias.fecha')
    ->from('imagenes')
    ->where('noticias.estado', $estado)
    ->where('imagenes.estado', $estado)
    //->group_by('imagenes.id_noticia')
  ->order_by('imagenes.id_noticia','ASC')
  ->join('noticias','imagenes.id_noticia = noticias.id_noticia','LEFT')
  ->get();

  $previous_section = null;
  foreach($query->result() as $row) {

   if ($row->id_noticia != $previous_section)
   {
    if ($previous_section != null)
    {
     $results[] = $section;
    }
    $section = array();
    $section['noticia']   = $row->id_noticia;
    $section['titulo']    = $row->titulo;
    $section['fecha']    = $row->fecha;
    //$section['imagenes']  = array();
    $previous_section    = $row->id_noticia;
   }
   $imagen = array();
   $imagen['imagen']   = $row->nimagen;
   $imagen['descripcion']  = $row->descripcion;
   $section['imagenes'][]  = $imagen;
  }
  if ($previous_section != 0)
  {
   $results[] = $section;
  }
  //print_r($results);
  return $results;


Messages In This Thread
Make array - Query with JOIN - by El Forum - 09-14-2012, 09:29 AM
Make array - Query with JOIN - by El Forum - 09-14-2012, 11:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB