Jump to content

chaning sql row order


swamp

Recommended Posts

Hi there, I've written a code that I can add files and edit their properties... I've basically got a list of all my files from a database - one of the fields is called $position - I need this to be able to select the position of the file.

 

The files default position in the list is '0' but I want to be able to make it go either down or up from form buttons. See the code below to see what I mean:

 

I was thinking it would be something like '$currentposition = $position" "$newposition = $currentposition + 1" but can't get it to work.

 

Could anyone lend a hand? Cheers!

 

Move down:

<?php
if (isset($_POST['move_down'])) {
	$file_ed = $_POST['edit_id'];
	$edit = mysql_query("UPDATE files SET
		position = 'WANT THIS TO BE ONE NUMBER LESS THAN $position'
	WHERE id = '".$_POST['pro_id']."'") or die (mysql_error());
	echo '<meta http-equiv="refresh" content="0;url=files.php?edit_id='?><?php echo $file_ed ?><?php echo'"/>';
	}
	?> 

 

Move up:

<?php
if (isset($_POST['move_up'])) {
	$file_ed = $_POST['edit_id'];
	$edit = mysql_query("UPDATE files SET
		position = 'WANT THIS TO BE ONE NUMBER MORE THAN $position'
	WHERE id = '".$_POST['pro_id']."'") or die (mysql_error());
	echo '<meta http-equiv="refresh" content="0;url=files.php?edit_id='?><?php echo $file_ed ?><?php echo'"/>';
	}
	?> 

Link to comment
https://forums.phpfreaks.com/topic/123167-chaning-sql-row-order/
Share on other sites

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.