Jump to content

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...
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.