• 0
Sign in to follow this  
emmanuelsiqueira30

Listar dados pelo INNER JOIN de outra tabela

Question

Pessoal não estou conseguindo listar os convidados nesta tela pela mesa e o responsável da mesa, deveria aparecer o número da mesa, o responsável e os convidados, não estou conseguindo acertar no INNER JOIN dos convidados, quem puder me ajudar já agradeço.

lista_mesas.php

<style>
	
	body {
		background-image: url("imagens/bg_adm.jpg");
		background-repeat: no-repeat;
		background-size: cover;
	}
	
	.btn-success{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-primary{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-warning{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-dark{
		height: 100px;
		width: 200px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
</style>
<?php 
  include("conexao.php");
  $dados = mysqli_query($con,"SELECT * FROM mesa");
?>

<!DOCTYPE html>
<html>

<head>

<?php
  include("sessao.php");
?>

<title>ControlTable</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

</head>

<body>

<div class="container-fluid">
	<div class="row">
	
	<div class="col-xs-12">
		<image class="image-responsive" src="imagens/logo.png" width="70%" style="width: 70%; margin: 0% 15%;"></image>
	</div>
	  
	  <div class="col-xs-12 list-inline">
	
		
		<?php
			while ($linha = mysqli_fetch_assoc($dados)) {
		?>
			<a href="visualiza_mesa.php?id=<?=$linha['id_mesa']?>"><h4 class="list-inline-item"><strong>MESA <?=$linha['nome_mesa']?></strong></h4>
		<?php 
			}// fim do while  
		?>
     
    </div>
	</div>
</div>

</body>

 </html>

visualiza_mesa.php

<style>
	
	body {
		background-image: url("imagens/bg_adm.jpg");
		background-repeat: no-repeat;
		background-size: cover;
	}
	
	.btn-success{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-primary{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-warning{
		height: 100px;
		width: 300px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
	
	.btn-dark{
		height: 100px;
		width: 200px;
		margin: 20px -150px; 
		position:relative;
		top:20%; 
		left:50%;
	}
</style>
<?php 
  include("conexao.php");
  
  $id = $_GET['id'];
  
?>

<!DOCTYPE html>
<html>

<head>

<?php
  include("sessao.php");
?>

<title>ControlTable</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

</head>

<body>

<div class="container-fluid">
	<div class="row">
	
	<div class="col-xs-12">
		<image class="image-responsive" src="imagens/logo.png" width="70%" style="width: 70%; margin: 0% 15%;"></image>
	</div>
	  
	  <div class="col-xs-12 list-inline">
	
		
		<?php
			$query = "SELECT * FROM responsavel INNER JOIN mesa ON responsavel.id_mesa_responsavel = mesa.id_mesa WHERE id_mesa_responsavel = $id";
			$dados = mysqli_query($con,$query);
			$result = mysqli_num_rows($dados);
			$linha = mysqli_fetch_assoc($dados);
			
		?>
		
		<?php
			if($result > 0){
		?>
				<h4><strong>MESA: <?=$linha['nome_mesa']?></strong></h4>
				<h4><strong>RESPONSÁVEL: <?=$linha['nome_pessoa']?></strong></h4>
				<h4><strong>CONTATO: <?=$linha['fonecel_pessoa']?></strong></h4>
		<?php
			}
			else {
		?>
				<div class='alert alert-success'>
					<h2><strong>MESA DISPONÍVEL <?=$linha['nome_mesa']?></strong></h2>
				</div>
		<?php
			}	
		?>
    </div>
	</div>
</div>

</body>

 </html>

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Olá!
Acredito que as informações fornecidas foram bem poucas.
Não sei onde o sr. grava as fks(foreign keys) do reponsável e dos convidados
 

Se puder, nos mostre a estrutura sql.
Talvez o adequado seria selecionar os dados from tabela-das-reservas e fazer os joins com as fks gravadas nela
fk_mesa
fk_responsavel
fks_convidados

Edited by wash

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this