Jump to content

[SOLVED] Adding an Order Field


gevans

Recommended Posts

Hey guys,

 

I'm updating a CMS to allow for re-ordering content. My first step is to add the `order` field to my db table.

 

After that's done I want to run a query to fill in the new field.

 

The table after adding the order field;

CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(44) NOT NULL,
  `url` varchar(44) NOT NULL,
  `parent_id` int(11) NOT NULL,
  `order` tinyint(1) NOT NULL,
  `active` varchar(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=89 ;

 

For each `parent_id` I want to increment the value in `order`. So for the 6 pages with a `parent_id` of 2 I want the `order` values to run from 1 to 6.

 

Is there a simple way to do this via a SQL without any PHP loops etc?

 

Cheers,

gevans

Link to comment
https://forums.phpfreaks.com/topic/180444-solved-adding-an-order-field/
Share on other sites

  • 2 weeks later...

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.