Insert multiple records in MySql based on an X value and add fixed values

0

I need to insert multiple records in the database, but without coming from a form. For example:

I have a value of 50 (it would be the number of records I need to insert) and a mooring id that needs to be the same for all records.

My question is: How do I insert these values without having to enter those values?

I've tried the examples here in the forum, but they all use values passed by forms.

In my case I do not have a form I only have the amount of records that I need to insert.

    
asked by anonymous 03.09.2018 / 17:21

1 answer

0

I've got a solution! I do not know if it is the correct solution for what I wanted, but it was the one I found.

I'll leave it here for anyone looking for something similar:

//Aqui eu defino a quantidade de registros que eu quero inserir. No caso aqui são 109 registros.
$valores = range(1, 109);

//Aqui posso definir o valor que eu preciso que seja igual em todos os registros adicionados
$id_empresa = '2';
$nome_pesquisa = 'Pesquisa Setor A';

for ($i = 0, $total = count($valores); $i < $total; $i++) {
    $conn->query("INSERT INTO pesquisa(id_empresa, nome) VALUES('$id_empresa','$nome_pesquisa')");
}
    
04.09.2018 / 00:50