Drupal 7:数据库查询文件

In page.tpl.php of Drupal, the following code has variable $page which contains the html codes that are required to render part of the webpage.

<?php if ($page['content']): ?>

I'm trying to retrieve the updated content from DB at an interval and update a DIV without refreshing the whole page. My question is, where can I find the DB query codes from which $page came about?

That content comes from inner node templates (if you are displaying node on that page) or i.e. view template....or...depending on what page you are displaying. But if we assume that you are displaying node page in some content type "player" you created content will "come" from template file "node--player.tpl.php"

https://www.drupal.org/node/1089656

Inside that file you can do database query (by using Drupal's database api) or even easier use Drupal's views module to query database:

https://www.drupal.org/project/views

page['content'] variable

When Drupal displays the "content" variable, think of it as big array of data that will be rendered in a specific section of the page. Before that happens, it either retrieves data from the block settings of the native interface (block visibility settings) or from custom modules that override this original settings like f.e. context (https://www.drupal.org/project/context).

>> Template files

The template files are kinda like the last stop where data is built and ready to be rendered and delivered to the client.

In general, the best practice is keep the render templates intact and keep the logic and variables manipulation at the pre_hook levels .

>> So if you do wanna have "programmatic" control over what you can display you can f.e.:

Render specific nodes with "node_load" function and then using node_view($node) f.e. $node = node_load(23); //23 is random a node id if (isset($node)) { $node_data = node_view($node,'default''); // here's my node display data print drupal_render($node_data); // here's my html }

Render templates that aggregate different data with the "theme_render_template" https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_render_template/7

Render views by using views_get_view('view name') like stated before.

Hooks like these might help you in adding/modifying the content you wish

template_preprocess : (hook templates

hook_node_view : (alter node array data before render)

page_alter : (alters page variables like content, header and so on)

hook_views_pre_render : (views is built, can alter render process)

hook_panels_alter : (for page manager and ctools approach)

>> Database queries Doing a straight query to the database can also be done through the database api and then rendered, but be aware you might miss out the drupal hook power and end up having high maintenance code that escapes the convenient and safer Drupal way.

Hope it helps!

What you are trying to do :

"I'm trying to retrieve the updated content from DB at an interval and update a > DIV without refreshing the whole page"

, is usually done with Javascript sending Http requests from the browser and not from PHP code executing server side in a Drupal template file, and is named AJAX. Doing AJAX with Drupal could be done in multiple ways, one of the recommended ones is with the use of the "Drupal AJAX Framework", resulting in PHP code with "Drupal AJAX API" calls server side that will generate for you the appropriate JavaScript client code renderer in the Drupal's output. The Drupal "Views" module may also help in this task, being "aware" of the Drupal AJAX framework. A good understanding of general AJAX mechanisms and of the Drupal AJAX framework are required to do this properly.