Thingfish47 Posted July 29, 2016 Share Posted July 29, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/ Share on other sites More sharing options...
ginerjm Posted July 29, 2016 Share Posted July 29, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535285 Share on other sites More sharing options...
Thingfish47 Posted July 29, 2016 Author Share Posted July 29, 2016 It is a db data set,but i was envisioning a 'done' button to update the database when things are as the user likes. So would it be possible to use JS for the moving about and the 'Done' button to save the amended data? Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535286 Share on other sites More sharing options...
ginerjm Posted July 29, 2016 Share Posted July 29, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535287 Share on other sites More sharing options...
Thingfish47 Posted July 29, 2016 Author Share Posted July 29, 2016 Many thanks! It's for the network at work so guys can predict the final standings for the UK Premier Division football (soccer) league. So I'm now off to read an ajax manual. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535289 Share on other sites More sharing options...
ginerjm Posted July 29, 2016 Share Posted July 29, 2016 They have ajax manuals? google a good example for an ajax call. Or use jquery. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535290 Share on other sites More sharing options...
Thingfish47 Posted July 29, 2016 Author Share Posted July 29, 2016 I bought a book called "Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning Php, Mysql, Javascript, Css & Html5)" Kindle Edition It has a chapter or two on Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535291 Share on other sites More sharing options...
kicken Posted July 30, 2016 Share Posted July 30, 2016 (edited) 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 July 30, 2016 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/301687-advice-on-a-problem-for-a-php-noob/#findComment-1535323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.