Skip to main content
added 420 characters in body
Source Link
WestieUK
  • 3.8k
  • 18
  • 34

I have a module which creates records in the db via drupal_write_record and this works perfectly. However I need to get the automatically assigned serial number for each record which is written into a variable.

Does anyone know how I can achieve this and get the index #?

I need the index variable to use in another table to create the reference...

Edit: Clives answer worked as below:

// Create object
$call = new stdClass;  
$call->uid = $user->uid;
$call->call_type = $call_type;
$call->cli = $cli;
$call->start_nid = NULL;
$call->timestamp = $timestamp;
    
// Insert call row in db  
drupal_write_record($table,$call);

// Test correct index
drupal_set_message($call->call_id);

I have a module which creates records in the db via drupal_write_record and this works perfectly. However I need to get the automatically assigned serial number for each record which is written into a variable.

Does anyone know how I can achieve this and get the index #?

I need the index variable to use in another table to create the reference...

I have a module which creates records in the db via drupal_write_record and this works perfectly. However I need to get the automatically assigned serial number for each record which is written into a variable.

Does anyone know how I can achieve this and get the index #?

I need the index variable to use in another table to create the reference...

Edit: Clives answer worked as below:

// Create object
$call = new stdClass;  
$call->uid = $user->uid;
$call->call_type = $call_type;
$call->cli = $cli;
$call->start_nid = NULL;
$call->timestamp = $timestamp;
    
// Insert call row in db  
drupal_write_record($table,$call);

// Test correct index
drupal_set_message($call->call_id);
Tweeted twitter.com/#!/StackDrupal/status/179897428986703872
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Source Link
WestieUK
  • 3.8k
  • 18
  • 34

Return inserted serial from drupal_write_record

I have a module which creates records in the db via drupal_write_record and this works perfectly. However I need to get the automatically assigned serial number for each record which is written into a variable.

Does anyone know how I can achieve this and get the index #?

I need the index variable to use in another table to create the reference...