Hello. There are two such tables: sqlfiddle.com/#!9/d307e. Tell me how, when adding new data to main, output the value from the color table (col1, col2, col3 ...) depending on what value of cololr was before? That is: I add data to main
$nnomer = "lux"; const SQL_INSERT_MAIN = ' INSERT INTO main (namenomer, datestart, dateend, color) values (?, ?, ?, ?) '; $addmt = $pdo->prepare(SQL_INSERT_MAIN); $add = $addmt->execute([$nnomer, $datestart, $dateend, $color]); The value of $ nnomer is equal to lux. In the lux database, the last value was col3, so when you add a new color, it should be equal to col4. As soon as the color in the main table reaches col6, then when you add a new color, it will be equal to col1. And so in a circle. If the value of $ nnomer was equal to vip in me, then the color should have been equal to col2, since the last value of color is col1. This is such a kind of auto_increment ... How to implement this?