Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] MySQL organitzation problem and results question
#1

[eluser]Isern Palaus[/eluser]
Hello,

I'm making a electronic commerce system and I'm having troubles with the tables of the database. I preferred to separate the content from the values to do it multilanguage.

So, the problem is that I need to do a loot of JOINs, like this:
Code:
private function _getProductsByCategoryId($id = 0, $activo = 1, $idioma = 1, $moneda = 1, $orden = 'nombre', $sentido = 'ASC', $total = 25, $inicio = 0)
    {
        $this->db->from('producto')
                 ->join('producto_descripcion', 'producto.idproducto = producto_descripcion.producto_idproducto', 'left')
                 ->join('fabricante', 'producto.fabricante_idfabricante = fabricante_idfabricante', 'left')
                 ->join('fabricante_descripcion','fabricante.idfabricante = fabricante_descripcion.fabricante_idfabricante', 'left')
                 ->join('producto_has_categoria', 'producto.idproducto = producto_has_categoria.producto_idproducto', 'left')
                 ->join('precio', 'producto.precio_idprecio = precio.idprecio', 'left')
                 ->join('monedas', 'precio.monedas_idmonedas = monedas.idmonedas', 'left');
                
        $ordenes = array(    'nombre'         =>    'producto_descripcion.nombre',
                            'precio'        =>    'precio.valor',
                            'fabricante'    =>    'fabricante_descripcion.nombre',
                            'referencia'    =>     'producto.referencia');
        
        if(in_array($orden, $ordenes))
            $this->db->order_by($orden, $sentido);
        else
            $this->db->order_by($ordenes['nombre'], $sentido);
            
        $this->db->where('producto.activo', $activo)
                 ->where('producto_has_categoria.categoria_idcategoria', $id)
                 ->where('producto_descripcion.idioma_ididioma', $idioma)
                 ->where('monedas.idmonedas', $moneda)
                 ->where('producto.borrado', 0);
                
        $this->db->distinct();
                
        $this->db->limit($total, $inicio);
            
        return $this->db->get();
    }

I'm using the tables: producto, producto_descripcion, fabricante, fabricante_descripcon, producto_has_categoria, precio, monedas.

The problem is that producto_descripcion, fabricante_descripcion and monedas have a value called 'name' and I don't know how to manage it and get the three values for the three entries in the database without having to modify the databases.

The other question is how to get the results. This produces a lot of results for every entry because I select all. The problem is that I don't want to use a foreach and set every row like $result['name'] = $row->name; , $result['date'] = $row->date; ... and I want to know if there is something to use and array. Actually I'm doing but this it only works for 1 result.

Thank you in advance.

Regards,
Isern


Messages In This Thread
[SOLVED] MySQL organitzation problem and results question - by El Forum - 11-06-2009, 07:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB