1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Save new list order - $5

Discussion in 'PHP' started by Python, Mar 1, 2010.

  1. #1
    Hi,
    I'm working on an event management system which deals with future events.

    I have a table called "events" with the following three fields...
    ID | name | when

    The "when" field contains a timestamp value of a future date. Here is some sample data... I've rounded off the timestamps to nearest 1000 for simplicity.

    1 | John | 1264491000
    2 | Mike | 1264492000
    3 | Paul | 1264496000
    4 | Mark | 1264498000

    In my apps front end these are displayed in order of their timestamp with the soonest being at the top.
    I've then used jQuery to make this into a drag + drop list which sends the new order back to a script... This is where I'm having trouble...

    The new order received via jQuery is held within an array holding the IDs of the rows from the "events" table.. for example...

    $newOrder = array(1, 2, 4, 3);
    PHP:
    Here's what needs to happen...

    If for example row ID #4 is moved up one so it is between #2 and #3 (array above shows this) then #4 timestamp should be set to = ((#2 timestamp) + (#3 timestamp ) / 2)... e.g. 1264494000
    So basically right in the middle...

    If however an event is moved so that it is the first or last item in the list it should add or deduct (depending if it becomes first or last event) 1000 seconds from the closest event.

    I've tried all sorts but cannot get this to work... Any help would be much appreciated.

    I'll gladly give $5 to whoever can explain a working solution.

    Thanks!
     
    Python, Mar 1, 2010 IP