2

I'm trying to use data captured within my drupal database to drive some analytics in another tool. I am trying to develop a view which gets the field data for a content type i've created. The db model seems rather complicated, can anyone give me any tips on how to join the tables together to find fields for a given content type.

Cheers A

  • Are trying to extract Drupal data from a non-Drupal application? – mpdonadio Jul 29 '13 at 16:59
  • I want to get data from drupal to something like tableau – brx_virgil Jul 30 '13 at 8:25
0

I'd definitely recommend using Views and one of the Views Data Export modules (I've used Views JSON with good results to get location data into an app powered by the google maps API)

EntityFieldQuery is THE way to query for Entity data in Drupal, however 1) in most cases, you'll be able to get the same data exported in a View much faster 2) once you have the data from an EntityFieldQuery, you still need to loop through the results and load the nodes, then format the data from the nodes into your output. Unless your output or your data needs are highly specialised this will deifnitely be more time and hassle than simply running it through Views

2

I would advise you to learn how to use the views module.

In order to achieve what you want. Make sure to install the views module first. To add a new view go to admin/structure/views/add and you should see the page below. Select the content type you want enter image description here

On the same page change teasers to fields. And then click continue and edit. It should take you to a new page. To add more fields from the content type you want, click on the Add link under the fields category. To make it better formatted, you can change the format type under the format category. Once you have added all your fields, click on the save button at the top.

enter image description here

  • 1
    Additionally if you use the Views JSON module you'll be able to spit out the view into an easily ingestible JSON object. – CR47 Jul 29 '13 at 18:38
  • Ideally i'd like to schedule the updates into the analytics tool, so getting the data into a given format is much more important than seeing it on the screen, i'd had a look at the views module, and whilst its very useful i'm not sure its quite right for what i want. - thanks for the tip off on views JSon though. – brx_virgil Jul 30 '13 at 8:23
2

There's a an API specifically for avoiding the need to manually join the tables together.

Check out How to use EntityFieldQuery, which

allows retrieval of a set of entities based on specified conditions.

A large advantage of using an EFQ instead of manually joining the tables is that it will keep working even if table structures change, such as for a D7 to D8 upgrade.

On a slightly related note, you may want to install the zero-conf Entity cache module, to improve the performance of the entity loading.

  • thanks. will have a look. I was hoping to avoid having to set up a dev environment for php though... – brx_virgil Jul 30 '13 at 8:25
1

For the case of exporting data for use by a statistical package for analysis, I would recommend using the Views module in conjunction with Views Data Export.

Views will allow you to to create custom queries over your database, configured fully through the UI. Views Data Export can take a View, and present it as CSV, XLS, or XML for consumption by another tool.

Directly querying a Drupal database from the outside is not an easy task, and is not recommended; the schema can vary as configuration changes. In some cases, it is possible to get the raw SQL that a View is using, and copy that to another tool. However, certain types of Views will not get all of the data as a single query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.