HOW TO Replace Data Between Table

0

Good morning. I have a problem, I am creating a system to improve the attendance of the students, who undergo a MAC release to be able to access the WI-FI of the college.

I created a register tab where all the entries go to the database, for example bd_cadastros and for table tb_mac , until then everything is right.

Now I'm going to create a page where a user sees all the registered MACs and releases them. My problem is this, I want to put next to each registered MAC a button that moves the MACs released from the tb_mac table to the tb_macsliberados table. How can I do this?

    
asked by anonymous 22.09.2016 / 13:14

2 answers

0

This move includes two operations. First, when selecting the MAC address to be released you perform a new insert in the tb_macsliberados table, at the end of the insert you apply a delete to the corresponding record in the table: tb_mac p>

I would personally choose to leave everything on the same table, just create a column of type "boolean" and mark it as "true" when releasing a Mac address.

    
22.09.2016 / 13:19
0

You can user INSERT INTO SELECT

INSERT INTO tb_macsliberados ('mac', 'idDoMac')
SELECT 'mac', 'idDoMac'
  FROM tb_mac
  WHERE idDoMac = "1"

In this case it will "move", in fact insert all the data that exists in tb_mac where the idDoMac é igual a 1 para o tb_macsliberated '.

  

You just need to restrict WHERE and it will "move" what you want there.

You can also create a UNIQUE in mac , in order not to publish records.

    
22.09.2016 / 15:29