Views 2 and Drupal - Adding a custom field to the views query

Greg's picture

Here's a quick rundown of how to add a field to Views 2 in Drupal.

It's fairly straightforward, but just in case someone is having difficulty this example should help you along. I'll try my best to explain what is happening.

Let's say for a moment you have some data in a table that pertains to a node. In this example, I'll have an item price in a table called views_price (this table was set up for expressly this purpose) which is keyed on a nid.

So basically we have this:

CREATE TABLE IF NOT EXISTS `views_price` (
  `nid` int(11) NOT NULL,
  `price` float NOT NULL,