MySql commit and rollback using php

First crate table using InnoDB storage engine of MySql.

CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;

<?php
$link = mysqli_connect("localhost", "root", "", "transaction");

/* check connection */
if (!$link) {
echo "Connect failed: ".mysqli_connect_error();
exit();
}

// set autocommit to off //
mysqli_autocommit($link, FALSE);

// Insert some values //
mysqli_query($link, "INSERT INTO users VALUES ('', 'Avi')");
mysqli_query($link, "INSERT INTO users VALUES ('', 'Sourav')");

// commit transaction //
$comm = mysqli_rollback($link);
$comm = mysqli_commit($link);
if (!$comm) {
echo "Transaction commit failed";
exit();
} else {
echo "Transaction committed";
}

// close connection //
mysqli_close($link);
?>

Order By Mysql

Reorder table using single query with php, jquery UI, MySql

Script

<script>

$(function() {

$( "#sortable" ).sortable({
update: function( event, ui ) {
var sortedIDs = $( "#sortable" ).sortable( "toArray" );

$.ajax({
type: "POST",
url: "general_ajax.php",
data: { mode: "SortMustKnows", sortedIDs: sortedIDs },
success : function(data){
alert( data );
}
});
}
});

$( "#sortable" ).disableSelection();
});

</script>

HTML

<ul id="sortable">

<li id="1"><span></span>Item 1</li>
<li id="2"><span></span>Item 2</li>
<li id="3"><span></span>Item 3</li>
<li id="4"><span></span>Item 4</li>
<li id="5"><span></span>Item 5</li>

</ul>

Mysql Query

$sortedIDs = '5,4,3,2,1';
@mysql_query("SELECT @i:=0;");
@mysql_query("UPDATE `table_name` SET  must_order = @i:=@i+1 where `primary_key` IN ($sortedIDs) ORDER BY FIELD(`primary_key`,$sortedIDs)");