Duplicate multiple Table Records at once

Asked

Viewed 802 times

0

I’m developing a payment system for my company, where there are two different types of accounts. Exporádicas (Ex. IPVA, Pen-Drive, etc.) and Fixed (e.g. Electricity Bill, Water, Telephone, Internet, etc.);

I have a table where only accounts with your type = 'fixed are displayed'.

What I would like to accomplish, which I could not and did not find at all, was...

a button that would take the Data being displayed in this table and duplicate it in the BD with Different ID and Value.

The idea is to remove the user’s work to relaunch accounts that will have exactly equal data, maybe differentiating maturity and value... and when clicking the button all values of the fixed type be duplicated...

inserir a descrição da imagem aqui

2 answers

4


I think it can help you, say you want to duplicate the registration data whose id 1 with another account name:

INSERT INTO CONTAS (VENCIMENTO, NOMEDACONTA, CEDENTE, FIDELIDADE, CC, VALORULTIMACONTA) 
SELECT VENCIMENTO, 'Escreva o que deseja substituir', CEDENTE, FIDELIDADE, CC, VALORULTIMACONTA FROM CONTAS WHERE IDCONTA = '1';
  • Thank you very much =D, it worked out, but it only goes once, how could I duplicate them all at once?

  • Run a query for each account.

  • Or change the condition WHERE if the data to be entered are exactly the same

0

Run the query within a loop for if the id is sequential, and is really all values.

    $qnt_reg = mysqli_num_rows($query_select);
    for ($i = 1; $i <= $qnt_reg; $i++) {
        //execute sua $query_insert aqui dentro mudando o id para $i se for sequencial; 
    };

Or condition which id will be selected by the query:

$query_select = 'SELECT * FROM tabela WHERE alguma coisa';
$query_rs = $conect->query($query_select);
while($row = mysqli_fetch_array($query_rs){
  //$id = $row['id'];
  $query_insert = "INSERT INTO table VALUES;
  $rs_insert = $conect->query($query_insert)
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.