Jump to content

Recommended Posts

Hi Knowledgeable Ones,

 

In a regular program, I would use a list-box of some sort, and have an 'up' button and a 'down button that would enable a selected item in the list to be swapped with the appropriate neighbour to achieve moving an item up or down the list so that the user could arrange the items in their desired order.

 

Could someone spare me some time to suggest how this could be done in a web page with php/html. Broad brush-strokes would probably be adequate.  I have huge amounts (47 years) of programming experience, but am new to php/html which I find a trifle frustrating.

Link to comment
https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/
Share on other sites

First you have to decide if you want to have an interaction with the server when you click the arrows. Is the change in the sequence meant to be temporary, ie, just visual, and not permanent as in having to do a db update to alter the sequence for future builds?

 

Just visual would be handled by JS code without the server interface. The latter option would either require a call to the server to effect the db update and the re-sending of the page to see the change. Or an ajax call, but that's a whole nother subject.

I'm sure it would be do-able. A Json array in the js that you manipulate and then pass back to the server with the Done button where it gets analyzed. Haven't done it myself but it's doable.

 

An ajax routine might be easier. The arrow click calls a js function that obtains the selected list item (value/text?) and makes the call to the server with that item's info and the direction to move it (up/down,+/-). The server makes the change in the db and passes back the complete new list which the js code then replaces on the web page. That would be simplest IF you know how to setup the ajax call.

There are lots of pre-written libraries out there to handle sorting lists using Javascript. You could grab one of those to implement the sorting then tie it into your PHP either with a form submit or a Ajax call, whichever you find easiest.

 

For example I've used Jquery UI's Sortable widget a few times in the past without much hassle. User's can drag-n-drop sort the elements in the DOM and you listen for the update event to know when the order has changed. When the order has changed you can inspect the dom to determine the new order then save that state into an input for a later form post or you could post it immediately with a ajax call.

 

Example

Edited by kicken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.