S
S
sasmoney2022-02-06 23:41:01
PHP
sasmoney, 2022-02-06 23:41:01

How to increase id by random value in sql table when adding?

How, when inserting data into a table, to simulate a faster growth of id, that is, increasing it by a certain amount, for some reason this code does the insertion as usual, without increasing the id by an amount from 1 to 15

$dddt = rand(1,15);
$insert_sql1 = "INSERT INTO `r_user` (`id`, `date_reg`, `online_seg`, `ip`, `ref_id`, `login`, `pass`, `hash`, `balance`, `social`) 
VALUES ('{id + $dddt}', '{$data}', '{$datas}', '{$ip}', '{$refid}', '{$login}', '{$pass}', '{$hash}', '{$bonus_reg}', '');";
mysql_query($insert_sql1);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2022-02-07
@sasmoney

SET @@auto_increment_increment=2;
SET @@auto_increment_offset=2;

S
Slava Rozhnev, 2022-02-07
@rozhnev

A rather strange task, but nevertheless it is possible like this (An example for understanding the principle)

for ($i=0; $i<3; $i++) {
  $dddt = rand(1,15);
  
  $insert_sql = "INSERT INTO events
    SELECT MAX(id) + {$dddt}, NOW(), 10 FROM events;";

  mysqli_query($mysqli, $insert_sql);
}

Check code online

R
rrambo, 2022-02-07
@rrambo

We add several records, then delete all but the last))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question