0

我需要重写 pagerquery,我尝试了几个添加标签的选项,extend(PagerDefault),但对我没有任何帮助:请帮忙。

我的版本 6 代码是:

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;

$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';

$args = array('uid' => $user->uid);

$sql = db_rewrite_sql($sql);

$sql_count = db_rewrite_sql($sql_count);

if ($pager) {

$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
dsm($result);

}

else {

$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}


$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}
4

2 回答 2

0

在不知道连接表的名称的情况下,这并不完整,但应该可以帮助您入门:

$query = db_select('node', 'n')
  ->fields('n', array('nid', 'sticky', 'title', 'created'))
  ->condition('n.uid', $user->uid)
  ->condition('n.type', 'case')
  ->condition('n.status', 1)
  ->extend('PagerDefault')
  ->limit(variable_get('default_nodes_main', 10))
  ->addTag('node_access')
  ->orderBy('col_name');

$query->join('table_to_join', 'table_alias', 'table_alias.nid = n.nid');

foreach ($query->execute() as $row) {
  // Do what you need to
}
于 2012-05-23T12:24:28.273 回答
0
if ($vidw == 'my_cases' or $vidw == 'my') {                   // including private
    switch ($sort_by) {
        case 'rated':
            $order = 'n.sticky DESC, vc.value DESC';
            $sort_join = 'LEFT OUTER JOIN {votingapi_cache} vc ON n.nid = vc.content_id AND vc.content_type = "node" AND vc.function = "average"';
            break;
        case 'discussed':
            $order = 'n.sticky DESC, nc.comment_count DESC';
            $sort_join = 'LEFT OUTER JOIN {node_comment_statistics} nc ON n.nid = nc.nid';
            break;
        case 'viewed':
            $order = 'n.sticky DESC, nc.totalcount DESC';
            $sort_join = 'LEFT OUTER JOIN {node_counter} nc ON n.nid = nc.nid';
            break;
        case 'recent':
        default:
            $order = 'n.sticky DESC, n.created DESC';
            $sort_join = '';
            break;
    }
    // from taxonomy_select_nodes
    $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
    $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
    $args = array('uid' => $user->uid);
    $sql = db_rewrite_sql($sql);
    $sql_count = db_rewrite_sql($sql_count);
    if ($pager) {
        $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
    }
    else {
        $result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
    }
    // $output .= taxonomy_render_nodes($result);
    $num_rows = FALSE;
    while ($node = db_fetch_object($result)) {
        $output .= node_view(node_load($node->nid), 1);
        $num_rows = TRUE;dsm($output);
    }
    if ($num_rows) {
        $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
    }
    else {
        $output .= '<p>'. t('There are currently no visible cases in this category.') .'</p>';
    }
}

在上面的 drupal 6 代码中,我更新了给我结果的查询,但 node_view() 和 theme() 不起作用。

于 2012-05-24T09:14:12.760 回答