0

i created a column name student id and set auto increment. but i want my registration number start from "ABC6788" . what i do ? please help me? my launguage is php mysql and yii framework.!

student_id type-int length-5 default-none A I -Checked

and how replace this code for automatic registration number in create form page??

 <div class="row-left">
            <?php echo $form->labelEx($info,'student_id'); ?>
            <?php echo $form->textField($info,'student_id'); ?>
            <span class="status">&nbsp;</span>
        </div>
user3261307
  • 3
  • 4
  • 8

3 Answers3

0

you can't use ABC6788 as an integer, so change to varchar maybe

and before save, get the last id, and set the primary accordingly,

OR

leave the primary key auto incremental as is and have another column with the value of your code

Developerium
  • 7,155
  • 5
  • 36
  • 56
0

Logic may be required behind auto-increment. get previous string. tokenize into ABC and 6788. increment second part by 1, and append it to first part. save it .

dvrnaidu
  • 151
  • 1
  • 1
  • 9
0

In MYSQL it is not possible to have auto-increment for char values. there fore you can make the student_id as integer and do auto-increment. At the time of display you can echo the characters separately and then the student id.

 <div class="row-left">
        <?php echo "ABC" . $form->labelEx($info,'student_id'); ?>
        <?php echo "ABC" . $form->textField($info,'student_id'); ?>
        <span class="status">&nbsp;</span>
    </div>

hope this will help..

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77
  • thanks sir ....but i want show always next registration number .on label on form ...how we show on label our next auto registration number on registration form ...besides textfield..on above code – user3261307 Feb 02 '14 at 09:09
  • its simple. in PHP there is a function called `lastInsertId()` using this function you can get the last inserted id in the table. with that number you can add +1. that's it. but first Google it and learn how to use `lastInsertId()` function in php. – Sathya Baman Feb 02 '14 at 09:16