English 中文(简体)
在Drupal6.x中获取用于检查重复标题的nid的数据库查询
原标题:database query for getting nid for checking duplicate title in Drupal 6.x
  • 时间:2011-02-17 15:32:52
  •  标签:
  • drupal-6

我想写一个SQL查询来查找节点ID(nid),该节点的标题与给定内容类型的给定标题(标题字段值的值)相匹配。我正在尝试以下操作-

function title_ajax_check_duplicate($title, $type) {

$results = db_query("SELECT nid FROM {node} WHERE title =  %s  AND type =  %s ", $title, $type);


  if (!empty($results)) {
    // This is a duplicate.
    return $results;
  }
  else {
    return FALSE;
  }
}

I am not able to solve this for a long time. Any help would be much appriciated. Thanks in advance.

最佳回答

$results将返回一个mysql资源,而不管实际结果如何。

签出db_fetch_array这实际上会包含结果。然后,您必须迭代结果数组才能找到重复的结果。

问题回答

将查询行更改为:

$result=db_result(db_query(“SELECT nid FROM{node}WHERE title=%s AND type=%s”,$title,$type)





相关问题
drupal form textfield #default_value not working

I am working on a custom module with multi-page form on drupal 6. I found that #default_value is not working when my #type => textfield . However, when #type => textarea , it displays correctly ...

Syntax Highlighting in Drupal

Which is the best module for Syntax Highligting in Drupal. I am using GeSHi for syntax highlighting my code. It was working fine then I installed a second module FCKeditor. Now GeSHi filter is not ...

Conditional link to node within views?

I have two content types, book and chapter. Each chapter node contains a node reference of the book to which it belongs. I have created a view which displays the title of each chapter for a given ...

Foreach in SQL?

I m not quite sure how to do this in SQL. Here it is in pseudocode: Take the list of nodes with content type X. For each node, take the value of field Y. Insert into term_nodes VALUES ((tid that ...

Drupal section accessible by role

I need to limit access of content on Drupal site based on the Drupal User s Role. http://site.com/managers/intro http://site.com/managers/reviews http://site.com/managers/up-for-raises The ...

Ungroup user menu in Drupal

I am using Drupal 6.x with Zen theme. Currently, the following 3 user functions are grouped under a menu, when accessing urls like http://domain.com/user Create new account / Log in / Request ...