Jump to content

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

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.