<?php include('config.php'); /* on form submission */ //print_r($_POST); /* split the value of the sortation */ $ids = explode(',',$_POST['sort_order']); /* run the update query for each id */ foreach($ids as $index=>$id) { $id = (int) $id; if($id != '') { $query = 'UPDATE elementy SET sort = '.($index + 1).' WHERE id = '.$id; mysql_query($query); echo $query; } } ?>