开发者

database query for getting nid for checking duplicate title in Drupal 6.x

开发者 https://www.devze.com 2023-02-11 22:31 出处:网络
I would like to write SQL query for finding the node ID (nid) for which title matches a given title (value of title field value) for a give content type. I am trying the following-

I would like to write SQL query for finding the node ID (nid) for which title matches a given title (value of title field value) for a give content type. I am trying the following-

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 advanc开发者_JAVA百科e.


$results will return a mysql resource regardless of actual results I think.

Checkout db_fetch_array this will actually contain the results. You'd then have to iterate over the array of results to find the duplicates.


Change you query line to:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号