snowman2344 Posted March 2, 2011 Share Posted March 2, 2011 I need some help with the above page. I cannot figure out the code to move the lines up and down with the arrow keys. The back end is MySQL here is an example Table name winning_numbers Id | date | day | numbers | bonus | page_order 1 | 01feb01 | Wed | 02 34 04 05 06 | 49 | 2 2 | 01feb01 | Wed | 02 34 04 05 06 | 49 | 1 3 | 01feb01 | Wed | 02 34 04 05 06 | 49 | 3 I have links on each image up and sown up link ?do=up&order='.$wn1[page_order].' down link ?do=down&order='.$wn1[page_order].' the PHP at the top of the page if ($_GET['do'] == 'up') { HERE IS THE MAGIC }else if ($_GET['do'] == 'down') { MORE MAGIC } thanks a bonus code might include deleting the line with the delete icon Thanks Again Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/ Share on other sites More sharing options...
Twistedweb123 Posted March 2, 2011 Share Posted March 2, 2011 Can I ask why you want to move each one individually up and down? An easier method would be to put the up/down arrows on every coloumn header, then link in a sort with that. So if you click the up arrow in date, it sorts ascending, and down would sort descending. If you put the arrows on all coloumn headers, you could sort by every coloum header rather than individual rows Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/#findComment-1181699 Share on other sites More sharing options...
snowman2344 Posted March 2, 2011 Author Share Posted March 2, 2011 I want to be able to move one record up or down in the order. Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/#findComment-1181806 Share on other sites More sharing options...
ZacTopher Posted March 2, 2011 Share Posted March 2, 2011 + and - 1? Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/#findComment-1181810 Share on other sites More sharing options...
snowman2344 Posted March 2, 2011 Author Share Posted March 2, 2011 im working whith this but is is not working correctly if ($_GET['do'] == 'up') { // Selected line $posQuery = "SELECT Id, page_order FROM winning_numbers WHERE page_order = '".$_GET['order']."'"; $posResult = mysql_query($posQuery) or die(mysql_error()); $posObj = mysql_fetch_object($posResult); // Position above selected line $moveQuery = "SELECT Id, page_order FROM winning_numbers WHERE page_order = ".$posObj->page_order."+1"; $moveResult = mysql_query($moveQuery) or die(mysql_error()); $moveObj = mysql_fetch_object($moveResult); $checkPos = mysql_query("SELECT page_order FROM winning_numbers ORDER BY page_order DESC LIMIT 1") or die(mysql_error()); $check = mysql_fetch_object($checkPos); if($posObj->page_order != $check->page_order) { mysql_query("UPDATE winning_numbers SET page_order=page_order-1 WHERE Id='".$moveObj->Id."'") or die(mysql_error()); mysql_query("UPDATE winning_numbers SET page_order=page_order+1 WHERE Id='".$posObj->Id."'") or die(mysql_error()); } }else if (isset($_GET['down'])) { // Selected line $posQuery = "SELECT Id, page_order FROM winning_numbers WHERE page_order = '".$_GET['order']."'"; $posResult = mysql_query($posQuery) or die(mysql_error()); $posObj = mysql_fetch_object($posResult); // Position above selected line $moveQuery = "SELECT Id, page_order FROM winning_numbers WHERE page_order = ".$posObj->page_order."-1"; $moveResult = mysql_query($moveQuery) or die(mysql_error()); $moveObj = mysql_fetch_object($moveResult); $checkPos = mysql_query("SELECT page_order FROM winning_numbers ORDER BY page_order DESC LIMIT 1") or die(mysql_error()); $check = mysql_fetch_object($checkPos); if($posObj->page_order != $check->page_order) { mysql_query("UPDATE winning_numbers SET page_order=page_order+1 WHERE Id='".$moveObj->Id."'") or die(mysql_error()); mysql_query("UPDATE winning_numbers SET page_order=page_order-1 WHERE Id='".$posObj->Id."'") or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/#findComment-1181818 Share on other sites More sharing options...
ManiacDan Posted March 2, 2011 Share Posted March 2, 2011 You're just switching the item with the item above or below it. Example: Moving item 1 (pageOrder 2) down to pageOrder 3. UPDATE table SET pageOrder = 2 WHERE pageOrder = 3; UPDATE table SET pageOrder = 3 WHERE id = 1; -Dan Quote Link to comment https://forums.phpfreaks.com/topic/229334-need-help-going-up-and-down/#findComment-1181819 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.