RE: Re: How to move data up and down within a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK, what you have to do is store a 'ordering' column in the database. You can
then use a function like this (taken from Mambo) :-

	/**
	/* Move a database row object up or down through the ordering
	/* @param int positive to move up, negative to move down
	/* @param string Additional conditions on the WHERE clause to limit
the effect
	*/
	function move( $direction, $where='' ) {
		$compops = array (-1 => '<', 0 => '=', 1 => '>');
		$relation = $compops[($direction>0)-($direction<0)];
		$ordering = ($relation == '<' ? 'DESC' : 'ASC');
		$k = $this->_tbl_key;
		$o1 = $this->ordering;
		$k1 = $this->$k;
		$database = isset($this->_db) ? $this->_db :
mamboDatabase::getInstance();
		$sql = "SELECT $k, ordering FROM $this->_tbl WHERE ordering
$relation $o1";
		$sql .= ($where ? "\n AND $where" : '').' ORDER BY ordering
'.$ordering.' LIMIT 1';
		$database->setQuery( $sql );
		if ($database->loadObject($row)) {
			$o2 = $row->ordering;
			$k2 = $row->$k;
			$sql = "UPDATE $this->_tbl SET ordering =
(ordering=$o1)*$o2 + (ordering=$o2)*$o1 WHERE $k = $k1 OR $k = $k2";
			$database->doSQL($sql);
		}
	}


Rob. 

-----Original Message-----
From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of arvindsri123
Sent: 30 May 2008 13:52
To: php-objects@xxxxxxxxxxxxxxx
Subject:  Re: How to move data up and down within a table

Hello,

I want to give to button in admin section to move data up after
clicking button and same for down.

I don't want to change every time through Script. I have seen thease
type of things in joomla admin, where u can move sequence up and down
after clicking on buttons.

Thanks,
Arvind

--- In php-objects@xxxxxxxxxxxxxxx, "Atkinson, Robert" <ratkinson@...>
wrote:
>
> In that case, you need to use 'ORDER BY column_name' in your SQL
statement to
> change the display sequence
> http://dev.mysql.com/doc/refman/5.0/en/select.html. 
> 
> Rob.
> 
> -----Original Message-----
> From: php-objects@xxxxxxxxxxxxxxx
[mailto:php-objects@xxxxxxxxxxxxxxx] On
> Behalf Of arvindsri123
> Sent: 30 May 2008 13:04
> To: php-objects@xxxxxxxxxxxxxxx
> Subject:  Re: How to move data up and down within a table
> 
> Hello,
> 
> I am storing data through PHP in my sql database. I need to move data
> up and down, so when i will retrieve data onm page it will come/show
> data according to that.. i m retriving data in ASC order.
> 
> Thanks, 
> 
> 
> ------------------------------------
> 
> Are you looking for a PHP job? Join the PHP Professionals directory Now!
> http://www.phpclasses.org/professionals/Yahoo! Groups Links
> 
> 
> 
> 
>
*****************************************************************************
******
> Any opinions expressed in email are those of the individual and not
necessarily those of the company. This email and any files transmitted
with it are confidential and solely for the use of the intended recipient 
> or entity to whom they are addressed. It may contain material
protected by attorney-client privilege. If you are not the intended
recipient, or a person responsible for delivering to the intended
recipient, be advised that you have received this email in error and
that any use is strictly prohibited.
> 
> Random House Group + 44 (0) 20 7840 8400
> http://www.randomhouse.co.uk
> http://www.booksattransworld.co.uk 
> http://www.kidsatrandomhouse.co.uk
> Generic email address - enquiries@...
> 
> Name & Registered Office:
> THE RANDOM HOUSE GROUP LIMITED
> 20 VAUXHALL BRIDGE ROAD
> LONDON
> SW1V 2SA
> Random House Group Ltd is registered in the United Kingdom with
company No. 00954009, VAT number 102838980
>
*****************************************************************************
******
>



------------------------------------

Are you looking for a PHP job? Join the PHP Professionals directory Now!
http://www.phpclasses.org/professionals/Yahoo! Groups Links




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux