Ver Mensaje Individual
  #11 (permalink)  
Antiguo 06/11/2012, 12:30
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

Gracias por tu ayuda rolygc, despues de darme varios dolores de cabeza lo logré y este es el código en cuestión:
Código PHP:
public function executeActionAuthor($action$author_id$article_id) {
    switch (
$action) {
        case 
'up':
        
$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_order $record->ORDEN_AUTORES != $record->ORDEN_AUTORES $record->ORDEN_AUTORES;

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

        
$previous_order $previous_order 1;
        
$actual_order $record->ORDEN_AUTORES 1;

        if (
$previous_record->ID_ARTICULO_AUTOR != $record->ID_ARTICULO_AUTOR) {
            
$update_previous = array('ORDEN_AUTORES' => $previous_order);
            
$this->db->where('ID_ARTICULO_AUTOR'$previous_record->ID_ARTICULO_AUTOR);
            
$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);
        }
        break;
        case 
'down':
        
$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_order $record->ORDEN_AUTORES 1;

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

        
$previous_order $previous_order 1;
        
$actual_order $record->ORDEN_AUTORES 1;

        if (!empty(
$previous_record)) {
            
$update_previous = array('ORDEN_AUTORES' => $previous_order);
            
$this->db->where('ID_ARTICULO_AUTOR'$previous_record->ID_ARTICULO_AUTOR);
            
$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);
        }
        break;
        case 
'delete':
        
$this->db->where('ID_ARTICULO'$article_id);
        
$this->db->where('ID_AUTOR'$author_id);
        
$this->db->delete('articulos_autores');
        break;
        default:
        break;
    }
    } 
Saludos y gracias a todos
__________________
Reynier Perez Mira
Skype: reynierpm
Site: http://www.reynierpm.com