Hello, all,
I am planning to build web site including database query function, forum and blogs. From the supporting documents, I am sure it is straight forward for the forum and blog part using the ready to use modules. But I am not sure Drupal database functions.
Here is my understanding: first I have to use CCK to design the database table fields, then use content template to show the data. Is this correct? Is there a better way to do it?
If CCK is used to create the table fields, should I take care the underline MySQL database? How many tables are there to support my new CCK content? Should I use MySQL interface to import my data to the database or Drupal has the function?
I am new to Drupal, but have general knowledge about MySQL, PHP and HTML. Could any experienced Drupal expert clarify these for our new comers like me? I think database query is very common need for a lot of websites. Thank you in advance, ldong

Comments

dnewkerk’s picture

I may not be able to answer all of your questions, but one important module for you to look at is the Views module, which alongside CCK, is one of the most powerful modules for Drupal. Views is essentially a smart query builder... per your settings, filters, arguments, etc, Views builds you a custom list of nodes, fields from within nodes, taxonomy terms, users, and much more (Views 2 has these new features - version 1 for Drupal 5 and below could only interface with the node table). After your View is built, Views module provides you with template file code (which you copy/paste into files with specific names it provides you with so it knows which template to use for a given View). In Views 1 (for Drupal 5) this is done with the Views Theming Wizard. In Views 2, click on "Theme: Information", under the Basic Settings category.

When needed (either for some query you can't make with Views, or for performance) you can also run Views' queries manually (Views 2 makes this especially easy and prints out the SQL queries for you to just copy and paste). Views has built in caching options to speed things up though. The general recommendation seems to be, use Views if you can and make use of its incredible integration with countless other modules and great features, and only resort to custom queries when you must.

Almost all Drupal sites I know of, from the small ones to the large/popular, make use of the Views module. Here's one nice example of a Drupal site that makes significant use of Views, CCK, Panels 2, and Nodequeue module... http://myplay.com

I wrote some tips earlier today regarding theming CCK with the aid of Contemplate module: http://drupal.org/node/282225
And here is a lesson I wrote that helps walk through the combination use of CCK, Views, Panels, and Nodequeue (lesson is for making a custom home/front page, however the info applies to the modules overall): http://drupal.org/node/278181#comment-910575
Here's a lesson I wrote on making a simple View (for Views 1, but concepts are applicable): http://drupal.org/node/168752#comment-263585
Here's a helpful screencast that illustrates a lot of the new functionality in Views 2: http://www.masteringdrupal.com/screencast/new-features-in-views2
I've collected some good resources here as well: http://forums.neverside.com/post/806952/#post806952

Regarding importing your data into Drupal, there are some modules that can help, such as Node Import and User Import. Personally I found it to be the best (for me) to manually import the data directly from the command line (though this took a bit of learning about the various tables data needed to be imported into... the most important tables for basic content are node and node_revisions). My reason for SQL importing was mostly due to having a huge amount of data though (about 21,000 users, 95,000 nodes, and 711,000 comments).

There may be some additional import helper modules... my suggestion is to visit the main modules listing - you can open this giant list, and using the Find feature of your web browser, locate anything you're looking for on the page.

-- David
absolutecross.com

kadog’s picture

HI, David,
Thank you very much for you quick response. I will digest your suggestion later on.
To import the data, I guess I can figure out the underline table structure through MySQL interface after design my nodes by CCK and view. I will deal with it later.
To start with, should I install Drupal 5 or 6? I found a lot of modules don't support Drupal 6 yet.
Thanks again, Ldong

dnewkerk’s picture

Here's some I wrote about Drupal 5 versus 6 a week or two ago: http://drupal.org/node/278072#comment-906353
(also click the link in my post there to see additional thoughts)

For importing, one other module I forget to mention (I haven't used it):
http://drupal.org/project/importexportapi

For my SQL import I found the chapters on the node and user systems in the "Pro Drupal Development" book to be very helpful in understanding what all the tables and fields meant and what their appropriate values needed to be. I also studied some of the code in various CMS conversion scripts and modules that translate other systems into Drupal. There may be similar references to the tables/fields online though I'm not sure of the link.

-- David
absolutecross.com

kadog’s picture

Hi, David,
Thank you again for your kind help. I guess it will be several month before my test site will work, I have installed Drupal 6.3 on my PC get familiar with Drupal.
But I still hesitate before jump in the CCK and view to customize nodes and my front page.
I find there are 4 basic content types in the installation including "story", "page", "blog" and "book". I guess I can very easily install forum model to let Drual have a content type "forum". Is this correct? If so, my question is: how to find a module which includes the same or similar content type I am looking for? In another work, before I start to make my own content type and related stuff, how do I confirm there is not ready to go module available?
Any suggestion or comments are appreciated, Thanks, ldong

dnewkerk’s picture

Yes, installing forum module would add the additional content type "forum".

It's unlikely you will find a module that provides you with a pre-defined content type that will meet your needs perfectly. That is the best thing about CCK module - you do not need any premade module to come up with types for you - just by clicking some buttons in CCK module, installing additional field types (such as Imagefield, Filefield, video, audio, computed, and many others), you can essentially design the exact content type you need for your site's purpose, and have complete control over how it works and how it is displayed (on the other hand, premade modules that have a lot of combined functionality built in often have a lot of functionality and templates hard-coded in, forcing you to adapt to that module's way rather than your own). If you are a programmer, you could even write your own different "field type" module to extend CCK's abilities, if the type you need doesn't yet exist (which would be much easier than trying to write a whole new module for that). Go to the CCK category of the modules section for instance for many options: http://drupal.org/project/Modules/category/88

As mentioned earlier, you should check the full module listing page, and try the drupal.org search engine to research what modules and functionality are already available. Once you see what options there are, you can make your choice about whether to go with a given module, or reproduce the exact functionality you need on your own with CCK, Views, etc.

-- David
absolutecross.com

BradleyT’s picture

Let's say we want to do 3 things

1) Create an admin form that let's someone enter city information (population, latitude/longitude, state, unemployment, google map).
2) Create a page that shows a list of all cities in our database
3) Create a nicely laid out page to show the specific city information

This requires NO programming.

1) To do this you would create a new CCK type (called city) and add the appropriate fields to it.
2) You would create a view and set the field to Node:Title and use a filter of Node:Type -> City
3) You would create a template page called node-city.tpl.php, use CSS and all of the fields used in the City type to get a nicely laid out page, and put it in your themes/template/ folder.

It's super simple and really powerful - all with no programming required. Of course if you know programming it can get even more powerful.

kadog’s picture

Hello BradleyT,
Thank you for the straight forward example. But how about joined tables? Let's say, I have another entity of state. Each state has its own population, area and other field. And each state has many cities in the state. Each city has its own population and area and so on. In database system, there should be two joined tables, so that I can run query. Can you explain how I can use Drupal to deal with this? Thanks,

kadog’s picture

..

WorldFallz’s picture

There's essentially 2 ways to interact with the drupal db. Through the drupal ui-- in which case you create content types using cck fields and present queries via views. I'm not really familiar with the schema behind cck, but I don't think it's as simple as one table per content type. And anyway, in this case, you really don't have to worry about the db and the schema-- the modules and DAL handle that.

Also, contemplate isn't required, but it is a convenient way to get more control over page presentation. cck/contemplate/views/panels will give you virtually unlimited control over presentation through the ui.

However, you can also do whatever you want manually with php, sql, html, or any combination thereof. You can enter sql and code directly into pages and blocks. There's also many very useful drupal functions available via the drupal api.

You can also mix and match if you want. Since you're new to drupal but not php/sql, i would suggest doing things via the drupal UI at first. It's the best way to learn it and understand its advantages and disadvantages. Then you can decide how much you wish to takeover manually.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

kadog’s picture

Hi, BradleyT,
Thank you for your quick and help guide. Now I create the content type "city" with name, address, area code, population and school. And I also create a view to list all the cities as list, grid or table.
Now the questions are:
1, how to create the "admin form" you mentioned to let user type in a parameter, click a button and run the query to get a result?
2, for each city, there many schools of different types. I want to only record 3 top high school and 3 college. When I show the results, I want group the 3 high schools together and 3 colleges together. How can I do this?
Thanks,
ldong

kadog’s picture

Hi,
To update my status (Drupal 6 with module "CCK", "Views" and "Custom (Form) destination" installed):
1, created a content type called 'city' with all the fields I need;
2 created a view to query 'city' with the fields I want to query as arguments (this can be set in view);
3 created a form (use form API) to get user input. It is not difficult.
4 trying to use module 'custom (Form) destination" to re-direct the submit button in the form to the view.

Things not sure:
1 how to theme within 'views' to change the 'view' output format. The help document is not informative.
2 For the state field in the from, I plan to put a dropdown list to let user select. It is better to have a map to have the selection. Not sure how to do it with drupal. If drupal can not do it, I will try javascript.

Please give suggestion on this or ask question if you want to learn something. ldong

Abbass’s picture

Hi,

I have been trying to do the samething as you but it is so hard, I have NO idea where to start!

I understand how to create a node, and make it look like a form, I understand how to create views and filter them but I have NOOO idea how to make sure views use the info in my form to query the database and send back information!!

Your help or anybody's for that matter will be greatly appreciated!

Thanks