Duplicate multiple Table Records at once

0

I'm developing a payment system for my company where there are two different types of accounts. (Eg IPVA, Pen-Drive, etc.) and Fixed (eg Electricity, Water, Telephone, Internet, etc.);

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

What I would like to accomplish, which I could not find or find in any way was ...

A button that would pick up the Data being displayed in this table and duplicate it in the DB with Different ID and Value.

The idea is to remove the work of the user by re-launching accounts that will have exactly the same data, perhaps differentiating the expiration and value ... and clicking the button all values of the fixed type are duplicated ...

    
asked by anonymous 12.04.2017 / 21:18

2 answers

4

I think it can help you, say you want to duplicate the data of the record 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';
    
12.04.2017 / 22:41
0

Execute the query within a for loop 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 what the id will be selecting 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)
}
    
13.04.2017 / 18:35