[eluser]SPeed_FANat1c[/eluser]
Just made change with codeigniter and sql. It is so much faster to code it.
Code:
function move_down($link_id)
{
//find a place of link with current id
$query = $this->db->select('vieta')->where('link_id',$link_id)->get('nuorodos');
$row = $query->row();
$place = $row->vieta;
//find an id of lower link
$query = $this->db->select('link_id')->where('vieta',$place+1)->get('nuorodos');
$row = $query->row();
$lower_link_id = $row->link_id;
//assign a new place for the current link
$data = array(
'vieta' => $place + 1
);
$query = $this->db->where('link_id',$link_id)->update('nuorodos', $data);
//assign a new place for lower link
if($query)
{
$data = array(
'vieta' => $place
);
$query = $this->db->where('link_id',$lower_link_id)->update('nuorodos', $data);
if($query)
$return_value = 'ok';
else $return_value = 'change_not_made';
}
else $return_value = 'change_not_made';
return $return_value;
}
I would like to ask is it necessary to check if update was succesfull? Those additional checking lines look not nice, and it is so litte chance that sql server will shut down or something. How do you think?