How to insert the next highest number into the database

前端 未结 3 1395
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 17:15

I have a piece of mysqli code which I written where it will insert values into the database:

$insertsql = \"
INSERT INTO Teacher
    (TeacherId, TeacherForename,         


        
3条回答
  •  失恋的感觉
    2021-01-26 17:29

    Well you can try this:

    First get the total number of rows in the table and increment it by 1 and put that into your new id For example:

    $selectUsers = mysql_query ("SELECT * FROM `Teacher`") or die(mysql_error());
    $num_rows = mysql_num_rows($selectUsers);
    
    $next_id = $num_rows+1;
    
    $new_id = 'T'.$next_id ;
    

    and after insert it into the table:

    ...

提交回复
热议问题