This is kinda more of logic question, because I already know how to code it, but it's coded in PHP/MySQL so I thought I'd post here.
I have a site, where users can register/login.
The user gets their own homepage where they can add different sections and links inside each section.
My problem is what to do with the order of the links. I want users to be able to customize the order.
What I've done so far is:
Each link has a 'place', which is just a number.
When you add a link, it get's the place of the last link in that section, and adds one, so as to put it in last place.
When you delete a link, it removes that link, then subtracts 1 from every links 'place' that come after it.
Now I want to make it so users can change the place. And I don't really know how I should go about it.
I guess you'd pick a new place for it, and some how renumber all the ones after it.
It's really confusing, is there any easier ways? Or how about examples
This is the current code when something get's deleted:
PHP Code:
$placesql = mysql_query("SELECT * FROM sections WHERE column_id = '$deletedcolumn' AND place > '$deletedplace'");
while ($needsupdate = mysql_fetch_array($placesql)) {
$newpid = $needsupdate[id];
$newp = $needsupdate[place] - 1;
mysql_query("UPDATE sections SET place = '$newp' WHERE id = '$newpid'");
}
I'm assuming the move code will have to be longer.
If anyone has any thoughts on this subject, I'd appreciate it.
Sorry for a rather messy post.