Ver Mensaje Individual
  #6 (permalink)  
Antiguo 06/11/2012, 10:25
reynierpm
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas
Mensajes: 140
Antigüedad: 13 años, 1 mes
Puntos: 1
Respuesta: Intercambiar valores en una consulta

Cita:
Iniciado por rolygc Ver Mensaje
Como sabes ke el padre inmediato es el 4 ?
Hmmm, este codigo que dejo a continuacion es Active Record de CI:
Código PHP:
$this->db->select('*');
        
$this->db->where('ID_ARTICULO'$article_id);
        
$this->db->where('ID_AUTOR'$author_id);
        
$record $this->db->get('articulos_autores')->row();

        
$previous_id $record->ID_ARTICULO_AUTOR != $record->ID_ARTICULO_AUTOR $record->ID_ARTICULO_AUTOR;

        
$this->db->select('*');
        
$this->db->where('ID_ARTICULO'$article_id);
        
$this->db->where('ID_ARTICULO_AUTOR'$previous_id);
        
$previous_record $this->db->get('articulos_autores')->row();

        if (empty(
$previous_record)) {
            
$previous_id $record->ID_ARTICULO_AUTOR 1;
        }

        
$this->db->select('*');
        
$this->db->where('ID_ARTICULO'$article_id);
        
$this->db->where('ID_ARTICULO_AUTOR'$previous_id);
        
$previous_record $this->db->get('articulos_autores')->row();

        
$previous_order $record->ORDEN_AUTORES;
        
$actual_order = !empty($previous_record) ? $previous_record->ORDEN_AUTORES $record->ORDEN_AUTORES;

//        print_r($record);
//        echo '<br>';
//        echo $previous_id;
//        echo '<br>';
//        print_r($previous_record);
//        echo '<br>';
//        echo $previous_order;
//        echo '<br>';
//        echo $actual_order;
//        die();

        
if (!empty($previous_record)) {
            
$update_previous = array('ORDEN_AUTORES' => $previous_order);
            
$this->db->where('ID_ARTICULO_AUTOR'$previous_id);
            
$this->db->update('articulos_autores'$update_previous);
        }

        
$update_actual = array('ORDEN_AUTORES' => $actual_order);
        
$this->db->where('ID_AUTOR'$author_id);
        
$this->db->where('ID_ARTICULO'$article_id);
        
$this->db->update('articulos_autores'$update_actual); 
Fijate que lo primero que hago es un SELECT y obtengo el ID que necesito en este caso seria ID_ARTICULO_AUTOR = 5 y luego le resto uno para obtener el padre pero no me funciona
__________________
Reynier Perez Mira
Skype: reynierpm
Site: http://www.reynierpm.com