Jump to content

[SOLVED] recursive -1 on position field


rondog

Recommended Posts

I have a list of items that a user can order by clicking 'move up' / 'move down'. These items are in my DB and when SELECTing I ORDER BY position. 'Position' is a field name that just go 1 through X.

 

The user also has the ability to delete an item by them clicking 'delete' on the specific item.

 

Say a user deletes Item 5 out of 10.

 

I will now have a gap in my position field - [1,2,3,4,6,7,8,9,10]

 

How can I ensure that when the users delete's an item, all items after it move their position number down 1 as well?

Link to comment
https://forums.phpfreaks.com/topic/156192-solved-recursive-1-on-position-field/
Share on other sites

Is there a problem with my query? Its returning false and just deleting the row:

<?php
function deleteProjectItem($id,$projID)
{
	$query = mysql_query("DELETE FROM projectData WHERE id = '$id' AND proj_id = '$projID'");
	$renum = mysql_query("UPDATE projectData SET position = 'position-1' WHERE id > '$id' AND projID = '$projID'");
	if ($renum)
	{
		return true;
	}
	else
	{
		return false;
	}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.