Reageer op reactie

Problem: You want to know the next id for the nodes. According to drupal you should use db_last_insert('table', 'field'). It returned allways zero for me. In essence the drupal function will execute SELECT LAST_INSERT_ID() in mysql. Even when I executed this directly in phpmyadmin is still returned 0 while my nid count was 20. Read this for the mysql explaination.

What is the solution to overcome this problem use SHOW TABLE STATUS WHERE Name='node' in the returned object you 'll find the next value for the autoincrement.

In the example we want to redirect after saving the node. But in the form alter we need to know which node id will be the next.

<?php
/**
 * Implementation of hook_form_alter().
 */
function modulex_form_alter(&$form$form_state$form_id) {
  if (
$form_id == 'teaser_node_form') {
    
$status db_fetch_object(db_query("SHOW TABLE STATUS WHERE Name='node'"));
    
$path implode('/', array('node'$status->Auto_increment'nodesinblock'));
    
$form['#redirect'] = $path;
  }
}
?>

Reageren

De inhoud van dit veld is privé en zal niet openbaar worden gemaakt.
  • Toegelaten HTML-tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Regels en paragrafen worden automatisch gesplitst.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Adressen van webpagina's en e-mailadressen worden automatisch naar links omgezet.

Meer informatie over formaatmogelijkheden

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.