Listar dados pelo INNER JOIN de outra tabela

Enviada por Emmanuel 
Emmanuel
Listar dados pelo INNER JOIN de outra tabela
13 de December de 2018 às 01:57PM
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>

<?php
// include("menu.php");
?>


<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";
$query = "SELECT * FROM responsavel INNER JOIN mesa ON responsavel.id_mesa_responsavel = mesa.id_mesa
INNER JOIN convidado ON responsavel.id_mesa_responsavel = convidado.id_convidado 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>
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.