4
Good evening I have the following BD in Mysql
CREATE TABLE IF NOT EXISTS `cad_cliente` (
`id_cliente` smallint(5) unsigned NOT NULL,
`nome_cliente` varchar(45) NOT NULL,
`nome_dr` varchar(45) NOT NULL,
`email_cliente` varchar(100) NOT NULL,
`data_nascimento_cliente` date NOT NULL,
`endereco_cliente` varchar(30) NOT NULL,
`bairro_cliente` varchar(20) NOT NULL,
`cep_cliente` varchar(20) NOT NULL,
`cidade_cliente` varchar(45) NOT NULL,
`estado_cliente` smallint(5) unsigned NOT NULL,
`observacao` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `cad_paciente` (
`id_paciente` smallint(5) unsigned NOT NULL,
`nome_paciente` varchar(45) NOT NULL,
`id_cliente` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `cad_trabalho` (
`id_trabalho` smallint(5) unsigned NOT NULL,
`id_cliente` varchar(45) NOT NULL,
`id_paciente` varchar(45) NOT NULL,
`id_dente` varchar(45) NOT NULL,
`id_servico` varchar(45) NOT NULL,
`id_cor` varchar(45) NOT NULL,
`observacao_trabalho` varchar(45) NOT NULL,
`data_entrada_trabalho` varchar(45) NOT NULL,
`data_saida_trabalho` varchar(45) NOT NULL,
`pronto_trabalho` varchar(45) NOT NULL,
`valor_trabalho` varchar(45) NOT NULL,
`pagamento_trabalho` varchar(45) NOT NULL,
`foto1_trabalho` varchar(45) NOT NULL,
`foto2_trabalho` varchar(45) NOT NULL,
`foto3_trabalho` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I would like to know how to display a query to the database via PHP so that when requesting a page that shows me the table data cad_trabalho
, this request search for patient and customer name data in the database.
Do you want to "display" a query or need help creating the query? (how do I display a query)... Have you tried creating this query or don’t know where to start?
– Paulo Roberto
Good evening @Pauloroberto, I know how to do in a way that would have to create several times the following command
$trabalho = mysql_query("select * from cad_trabalho where id_trabalho='".$id_trabalho."'");
and$cliente = mysql_query("select * from cad_cliente where id_cliente='".$id_cliente."'");
and$paciente = mysql_query("select * from cad_paciente where id_paciente='".$id_paciente."'");
I’ve been researching about relationships of tables which has a simpler way of making that query I don’t know where to start– Cristiano Cardoso Silva
and to display would have to do as follows
while($C = mysql_fetch_array($cliente)) {
 $nome_cliente = $V["nome_cliente"];
while($P = mysql_fetch_array($paciente)) {
 $nome_paciente = $V["nome_paciente"];
while($T = mysql_fetch_array($trabalho)) {
 $id_trabalho = $V["nome_trabalho"];
So on to receive all necessary data– Cristiano Cardoso Silva
@Cristianocardososilva Use the field of answer below to present solutions, here is to ask for suggestions or suggest improvements
– Maicon Carraro
Good evening @Maiconcarraro I’m just informing to Paulo Roberto how I make my requests today
– Cristiano Cardoso Silva
Yes, I understand, but here it is mt short the field
– Maicon Carraro