There are 4 columns in my relationship table:
- ID
- CID - course id
- LID - related lesson unique id
- course_based_id - explanation below
There are bunch of lessons and courses with unique id's in another tables called lessons and courses. This table is, asociation table between them. Basically it assigns unique lesson id to unique course id. But.. There is need for course based id of lesson. I mean, for example lets take a look at first and second rows from screenshot

Lid 1 is course 2's first lesson, lid 3 is course 2's second lesson... And so on. So if I insert cid 2, lid 128 it must third lesson of course 2.
Now, the problem is, I want to auto generate this number while insert:
$q="INSERT INTO `courses-lessons` (`cid`, `lid`) VALUES (?,?)";
but have no idea how to do it. Some MySQL function? or something inside query?