Relationship between tables

Asked

Viewed 101 times

1

I have a certain table already created and populated:

CREATE TABLE `formulario` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `nome` varbinary(50) DEFAULT NULL,
  `carteira` varchar(30) NOT NULL,
  `tipo_ocorrencia` varchar(13) NOT NULL,
  `contato` varchar(20) DEFAULT NULL,
  `tel` varchar(50) DEFAULT NULL,
  `mensagem` text NOT NULL,
  `data` varchar(10) NOT NULL,
  `hora` varchar(8) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3744 DEFAULT CHARSET=utf8;

I am creating this table now:

CREATE TABLE `preformulario` ( 
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`r1` VARCHAR( 3 ) NOT NULL ,
`r2` VARCHAR( 160 ) NOT NULL ,
`r3` VARCHAR( 160 ) NOT NULL ,
`r4` VARCHAR( 160 ) NOT NULL ) ENGINE = MYISAM;

I need to export a table that reconciles the two tables above! The user will inform the table data preformulario and then begin to inform the table data formulario. As I explained, the table formulario is already populated... Your ID is in 3744.
I have very little... experience with Mysql. I need to know if I need to create a third table reconciling the two I mentioned or if there is a solution in my PHP that already reconciles these data?

2 answers

0

Voce does not need a third table , I created a view or a proc or even a select that lists the data that Voce wants to show to the user in Sersert take the form table id and insert it into the other table. That’s a many-to-many relationship

  • Hi, @Regis Faria. I don’t quite understand, my dear! What did you mean by "Insert pege"? How did you explain how I can link the same user? Like, if the guy fills the first table and fills the second, how do I link the two inserts... Display the two in a single SELECT?

0

list data from the two related tables via a select, view or procudure this to display to the user. In this select Voce will bring the table id formulario which is what Voce needs to do the Insert in the`preformular table That’s usually how you do it.

  • That’s not it. I haven’t clarified the doubt. I don’t depend on the table formulário to make Insert in preformulario. I just need to reconcile what was inserted in preformulario which is inserted in formulário. The same user will enter data in both.

Browser other questions tagged

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