HOW to Replace Data Between Table

Asked

Viewed 24 times

0

Good morning. I’m having a problem, I’m creating a system to improve the attendance of students, who go through a release of MAC to be able to access the college’s WI-FI.

I created a registration tab where all the entries go to the bank, for example bd_cadastros and to table tb_mac, so far so good.

Now I will create a page where a user sees all registered Mac and make the release. My problem is the following, I want to put next to each registered MAC a button that moves the MAC released from the table tb_mac to the table tb_macsliberados. How can I do that?

  • 2

    Welcome(a) to the Stack Overflow in English! Have you tried anything? Have any specific questions? Here is not the best place to ask for examples or generic tutorials. I suggest you do the tour and read about How to ask.

2 answers

0

That drive includes two operations. First, while selecting the Mac address to be released you perform a new Insert in table tb_macsliberados, at the end of the Insert you apply a delete to the corresponding record in the table: tb_mac

Already the mentioned button is something simple, this will be presented in the preview layer ("html, js and css").

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

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", actually insert all the data that exists in the tb_mac where the idDoMacé igual a 1 para otb_macsliberados`.

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

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

Browser other questions tagged

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