Jump to content

Up/Down ordered list problem !!


Skylight_lady

Recommended Posts

Hi Guys,

 

I have an up/down ordered list to display which services should be ahead of the others. Below is my code:

 

$menu_id = $_GET['page_id'];
			$page_order = $_GET['page_order'];
			if ($_GET['do'] == 'up') {
				mysql_query("UPDATE services SET menu_order = '$page_order' +1 WHERE ID != '$menu_id' AND menu_order < '$page_order'") or die(mysql_error());
				mysql_query("UPDATE services SET menu_order = menu_order -1 WHERE ID = '$menu_id'") or die(mysql_error());
				header("Location: /services/view/");
			} if ($_GET['do'] == 'down') {
				mysql_query("UPDATE services SET menu_order = '$page_order' -1 WHERE ID != '$menu_id'");
				mysql_query("UPDATE services SET menu_order = menu_order +1 WHERE ID = '$menu_id'"); 
				header("Location: /services/view/");
			}

 

The code above is accessed via this link:

<a href="/services/view/index.php?do=up&page_id=<?php echo $id; ?>&page_order=<?php echo $menu_order; ?>">

 

Now, if i have a table setup as:

 

IDmenu_order

21

53

42

 

And click on the links button to go "up" one for the ID "5" i get the following:

IDmenu_order

24

52

44

 

I can't seem to see what is wrong with the code but  :wtf: ...... the ID of 2 and 4 are wrong. If i click the down button on the same ID 5 which will have do=down in the link then i get:

IDmenu_order

21

53

41

 

I would appreciate any help with this.

Link to comment
https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/
Share on other sites

I should learn to scroll down. Thanks, have it sorted. Now i have a challange......... PAGINATION. I've seen the tutorial phpfreaks but it is confusing as it's asking me to add numbers to a column when i'm clueless on:

 

  • adding it to my original table
  • how to add this numbers column's data when all the data in that page is inserted from a different page

Archived

This topic is now archived and is closed to further replies.

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