Make array - Query with JOIN - El Forum - 09-14-2012
[eluser]VolkS[/eluser]
hello, sorry for my poor English.
Code: $query =
$this->db->select('imagenes.*,imagenes.imagen as nimagen, noticias.id_noticia, noticias.estado,noticias.titulo')
->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();
return $query->result();
how i can make a array?
Example:
Notice 1:
--Image1
--Image2
--Image3
Notice 2:
--Image1
--Image2
--Image3
Thanks!!!
Make array - Query with JOIN - El Forum - 09-14-2012
[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;
|