Well, this is much the same as any CMS system where you are able to
sort the contents by your own, in your case song titles.

One way to solve this is by using form fields together with your listings
so that you have some sort of link to the posts in your database. You
also need a field in the database that keeps track of the sort. You also
need abit of javascript.

EG.

ID, SONG TITLE, SORTER

Lets have some data,
1, Limbo, 5
2, Bimbo, 6
3, Cimba, 1

This will be presented :
Cimba (1)
Limbo (5)
Bimbo (6)

When you print out the HTML I would include some hidden form
fields for each item so that I know what to sort / move up / down.

Eg.
hidden name="data[item][$i]" value="ID"/ Cimba (hidden ID=3)
hidden name="data[item][$i]" value="ID"/ Limbo (hidden ID=1)
hidden name="data[item][$i]" value="ID"/ Bimbo (hidden ID=2)

Each line would need some sort of javascript command, like
javascript="moveup($i)"

Assign this moveup() variable to anything, eg. hidden name=check value="**"
so we
can access it from PHP.

Your javascript will then submit the form with ALL variables mentioned
above.

So do we now know?

1. We have a complete array of all the records from the HTML page in
$_POST["data"]["item"]
2. We also know what database ID each item has with the twin array
$_POST["data"]["id"]

If we were to move something up, now we have a way of doing so, since :
Say you entered moveup(2), which the javascript assigned the "2" to a
variable "check" which we
now know as $_POST["check"]. Moving 2 (Which is 3 since we start counting
from 0) we know
that 2 is supposed to switch places with 1, meaning the SORTER will be
switched.

so we know the following :

$data = $_POST["item"];
$sourceID      = $data["item"][$_POST["check"]];
$destinationID = $data["item"][$_POST["check"]-1];

The rest would be to do the SQL queries for the SORTER field,
A=C,
B=A,
C=B

meaning :
tempA = select sorter from blabla wher id = source
tempB = select sorter from blabla wher id = destination
update blabla set sorter=destination where id = source
update blabla set sorter=source where id = destination

This was all abit quick'n'dirty as I call it, but I hope you got the general
idea on how to do it. You need ofcourse alot more debugging and such
for the final code (Like you cand moveUP the first row, since that would
make the array go from 0 to -1 which doesnt make sence).

-- 
-- 
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------

"Matt Grimm" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I apologize if this message is a repeat; I've had trouble posting with
> Thunderbird.
>
> I'm interested in how you folks would approach the following issue:
>
> You have a list of data, in a user-defined sequence.  For instance, a list
> of song titles that can be rearranged on a web page in any order. I don't
> think I have the best grasp of the logic involved, and as such, the
problem
> is a real pain for me.  I use this approach:
>
> -If adding, records after or equal to the new (requested) spot are
> incremented
> -If moving up, records before the current spot and after or equal to the
> new spot are incremented
> -If moving down, records after the current spot and before or equal to the
> new spot are decremented
> -If deleting, records after or equal to the current spot are decremented
>
> Is there some MySQL or PHP function that will handle this sort of
> reordering business, or is there possibly a simpler logic I could use?
>
> Thanks,
> Matt
> [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to