[support] How to get the auto-increment value

prothero prothero at geol.ucsb.edu
Tue Mar 29 01:51:33 UTC 2011


Austin:
Look for the AUTO_INCREMENT value. It is settable. Google it.
I forget the actual sql syntax. I use Navicat to manage my databases  
and it makes this kind of thing very easy.
Bill

William A. Prothero
http://earthednet.org/



On Mar 28, 2011, at 5:50 PM, Austin Einter wrote:

> Hi David
> I did that, but the auto-increment field values starts from a high  
> integer value (approx 15594). Then onwards for each row it is  
> incremented by 1.
> Though I do not see any problem with that (starting from high  
> value), I would have liked the value to start from 0 or 1 and keep  
> incrementing for each row.
> Is there any-way, I can force the value to start from 0 or 1.
>
> Best Regards
> Austin
> On Mon, Mar 28, 2011 at 11:42 PM, Metzler, David <metzlerd at evergreen.edu 
> > wrote:
>
> Do not include cid in the insert statement and it should  
> autoincrement for you.
>
> -----Original Message-----
> From: support-bounces at drupal.org on behalf of Austin Einter
> Sent: Mon 3/28/2011 03:04
> To: support at drupal.org; development at drupal.org
> Subject: [support] How to get the auto-increment value
>
> Hi All
> I have a table, where 'cid' field is of type "serial".
>
> Schema declaration is ->  *"'cid' => array('type' => 'serial',  
> 'unsigned' =>
> TRUE, 'not null' => TRUE, ),"*
>
> Aim is to have an incremented value for it.
> The code is as below
>
> *$lastid = 0;
>  for($delta = 0; $delta < $all_companies; $delta++)
>  {
>  $lastid = db_last_insert_id(rs_companies, cid) + 1;
>      db_query(
>    'INSERT INTO {rs_companies} ( cid, uid, prevcompany, joindate,
> releasedate) '
>      ."VALUES (%d, '%d', '%s', '%d', '%d')",
>  $lastid,  *
>
> With this, I find this 'cid' field is not auto incrementing.  Any  
> idea,
> whats the wrong here.
>
> Best Regards
> Austin.
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
> -- 
> [ Drupal support list | http://lists.drupal.org/ ]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110328/ce18f7eb/attachment.html 


More information about the support mailing list