i am new to drupal 7.
开发者_运维百科$sql = "SELECT nid, title FROM {node} n
WHERE nid $sql_op %d
AND type IN (" . implode(',', $quoted_types) . ")
AND status = 1
ORDER BY nid $order
LIMIT 1";
$result = db_query($sql, $current_node->nid, $type);
$data = db_fetch_object($result);
how to put the above sql query upgrade to drupal 7 thank you.
This looks like this for D7:
$result = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->condition('n.nid', $current_node->nid, $sql_op)
->condition('type', $type)
->condition('status', 1)
->orderBy('nid', $order)
->range(0, 1)
->execute();
$data = $result->fetchObject();
Untested, of course, so report back if this works. Also make sure that you use the correct types, not sure why the D6 version uses an IN statement for the type but then only has a single $type. Note that in the above code, you can either pass a single value or an array of values to condition(), both works.
Try this :
$result = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->condition('n.nid', $current_node->nid, $sql_op)
->condition('type', $quoted_types, 'IN')
->condition('status', 1)
->orderBy('nid', $order)
->range(0, 1)
->execute();
$data = $result->fetchObject();
精彩评论