Jump to content

Need help going up and down


snowman2344

Recommended Posts

lottophp.jpg

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());	
		}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.