Access an element that comes within an array

0

I was able to access the first image, but I do not know how to move in the other tree. my current code is:

 $datacategory = $this->Restaurant_mod->category(4);
        for($i=0;$i<count($datacategory);$i++){
            $datacategory[$i]['image'] = 'cambio de ruta';
        }
        $this->response($datacategory);

How can I access the next tree and so on ... Greetings!

    
asked by DoubleM 11.06.2018 в 18:09
source

2 answers

1

Try it like this:

$datacategory = $this->Restaurant_mod->category(4);
    for($i=0;$i<count($datacategory);$i++){
        $datacategory[$i]['image'] = 'cambio de ruta';
        foreach($datacategory[$i]['products'] as $i => $product) {
            $product['image'] = 'notfound.png';
        }
    }
    $this->response($datacategory);
    
answered by 11.06.2018 в 18:15
0

I do it this way, for example if I'm going to show the list of products or something like this: in my index:

public function index()
{
   $data = array();
   $this->load->model("Modeloproducto");
   $this->data["productos"] = $this->Modeloproductos->mostrar();
   $this->load->view("paginas/lista_peliculas", $this->data);
}

In my "Product Model" product model

function mostrar(){
  $this->db->from("Producto");
  $q = $this->db->get();
  return $q->result();
}

And in my view:

<table>

 <thead>
   <tr>Encabezados de la tabla</tr>
 </thead>

 <tbody>
   <?php 
      foreach ($productos as $producto) {
        echo "<td>$producto->nombre</td>
              <td>$producto->descripcion</td>
              <td>
                <img src=\" " . base_url() . "/imagen/miniatura/$producto->imagen \">
              </td>
             ";

      }
 </tbody>

</table>

If it works for you, mark my answer as the correct one.

    
answered by 30.06.2018 в 05:01