To Swap Database Row in PHP

Today I am going to show one more demo which is for to swap database table row like in Joomla for sorting or ordering a table.Here I am going to show you how to swap the id’s of rows of the particular table.

Basically, we are doing swapping to SWAP values of two variables with using a third variable so with the use this basic concept, I have created one demo which swap database rows with PHP coding.In order to switch the position of rows, you will need to set the Order(ASC, DESC) value of each row and then you can update rows with swap code.a

Let’s have a look into coding done by me so you get the idea how swapping of rows is possible.

Here above code, You will get previd and nextid. Using previd and nextid find out the previous and next row from swap rows Table.And after fetching the id, call the row_swap function which will update the row into the table and your data will be updated.

That’s it. Now you are ready to swap rows from the database.Have a look at the working Demo here.

Post navigation

About Author

Bhumi

Bhumi shah is currently working with leading web development company as a Software Analyst and also the founder of the Creativedev. She has immense interest in programming and web designing.She is passionate about technical blogging and almost versatile in terms of programming across various languages & frameworks such as PHP,MySQL WordPress, Twitter Bootstrap, AngularJS, HTML5, CSS3, jQuery and more.