Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ednojunior96

Exibir dados de tabelas Relacionadas

Recommended Posts

Boa Tarde galera estou precisando de mais ajuda de voces.

 

Eu duas tabelas e fiz o relacionamento entre elas funcionou blza

 

As tabelas

 

Fazendas Serviços

idfazenda idservicos

numero idfazenda

proprietario idcategoria

propriedade data

regiao servicos

 

 

Ai uso

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos ON fazendas.idfazenda=servicos.idfazenda');

$query = $db->Execute($sql);
$row = $query->FetchRow();
Ai funciona blza puxa os dados mais tem uma hora que preciso separar os serviços por categoria
Por exemplo Aqui vai exibir os serviços da categoria A
Agora somente da categoria B
não consigo fazer essa parte

Compartilhar este post


Link para o post
Compartilhar em outros sites

ai vou ter que fazer $sql = ("SELECT * FROM fazendas LEFT JOIN servicos ON fazendas.idfazenda=servicos.idfazenda group by servicos.idcategoria ');

$query = $db->Execute($sql);
$row = $query->FetchRow();
{
não teria que colocar no idcategoria=1 para puxar so dados da 1 não ?

Compartilhar este post


Link para o post
Compartilhar em outros sites
SELECT * FROM fazendas LEFT JOIN servicos

 ON fazendas.idfazenda=servicos.idfazenda

and idcategoria= 1 

group by servicos.idcategoria

Tá meio corrido aqui, tenta isso aí. Mas as outras categorias ficarão de fora

Compartilhar este post


Link para o post
Compartilhar em outros sites

1 outra possibilidade é o order by;

tente ahe...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse é o codigo que estou usando certinho

 

 

<?php

include "compartilha/conf/conectar.php";

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos ON fazendas.idfazenda=servicos.idfazenda WHERE fazendas.idfazenda=".(($_GET['id'])?($_GET['id']) :($_POST['id'])));

 

 

 

$query = $db->Execute($sql);

$row = $query->FetchRow();

?>

 

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

 

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta name="description" content="">

<meta name="author" content="ThemeBucket">

<link rel="shortcut icon" href="images/favicon.html">

 

<title>Basic Table</title>

 

<!--Core CSS -->

<link href="bs3/css/bootstrap.min.css" rel="stylesheet">

<link href="css/bootstrap-reset.css" rel="stylesheet">

<link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />

 

<!-- Custom styles for this template -->

<link href="css/style.css" rel="stylesheet">

<link href="css/style-responsive.css" rel="stylesheet" />

 

<!-- Just for debugging purposes. Don't actually copy this line! -->

<!--[if lt IE 9]><script src="js/ie8/ie8-responsive-file-warning.js"></script><![endif]-->

 

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

<!--[if lt IE 9]>

<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>

<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>

<![endif]-->

</head>

 

<body>

<body class="full-width">

<section id="container" >

<!--header start-->

<header class="header fixed-top">

<div class="navbar-header">

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">

<span class="fa fa-bar"></span>

<span class="fa fa-bar"></span>

<span class="fa fa-bar"></span>

</button>

<!--logo start-->

<div class="brand">

 

<a href="index-2.html" class="logo">

<img src="images/logo.png" alt="">

</a>

<div class="sidebar-toggle-box">

<div class="fa fa-bars"></div>

</div>

</div>

<!--logo end-->

 

 

<div class="horizontal-menu navbar-collapse collapse ">

<ul class="nav navbar-nav">

<li><a href="index-2.html">Dashboard</a></li>

<li class="active"><a href="#">Components</a></li>

<li class="dropdown">

<a data-toggle="dropdown" data-hover="dropdown" class="dropdown-toggle" href="#">UI Kits <b class=" fa fa-angle-down"></b></a>

<ul class="dropdown-menu">

<li><a href="general.html">General</a></li>

<li><a href="buttons.html">Buttons</a></li>

<li><a href="font_awesome.html">Font Awesome</a></li>

</ul>

</li>

<li><a href="basic_table.html">Sample Menu</a></li>

<li class="dropdown">

<a data-toggle="dropdown" data-hover="dropdown" class="dropdown-toggle" href="#">Extra <b class=" fa fa-angle-down"></b></a>

<ul class="dropdown-menu">

<li><a href="blank.html">Blank Page</a></li>

<li><a href="boxed_page.html">Boxed Page</a></li>

<li><a href="profile.html">Profile</a></li>

<li><a href="404.html">404 Error Page</a></li>

<li><a href="500.html">500 Error Page</a></li>

</ul>

</li>

</ul>

 

</div>

 

 

 

<div class="nav notify-row" id="top_menu">

<!-- notification start -->

<ul class="nav top-menu">

<!-- settings start -->

<li class="dropdown">

<a data-toggle="dropdown" class="dropdown-toggle" href="#">

<i class="fa fa-tasks"></i>

<span class="badge bg-success">8</span>

</a>

<ul class="dropdown-menu extended tasks-bar">

<li>

<p class="">You have 8 pending tasks</p>

</li>

<li>

<a href="#">

<div class="task-info clearfix">

<div class="desc pull-left">

<h5>Target Sell</h5>

<p>25% , Deadline 12 June’13</p>

</div>

<span class="notification-pie-chart pull-right" data-percent="45">

<span class="percent"></span>

</span>

</div>

</a>

</li>

<li>

<a href="#">

<div class="task-info clearfix">

<div class="desc pull-left">

<h5>Product Delivery</h5>

<p>45% , Deadline 12 June’13</p>

</div>

<span class="notification-pie-chart pull-right" data-percent="78">

<span class="percent"></span>

</span>

</div>

</a>

</li>

<li>

<a href="#">

<div class="task-info clearfix">

<div class="desc pull-left">

<h5>Payment collection</h5>

<p>87% , Deadline 12 June’13</p>

</div>

<span class="notification-pie-chart pull-right" data-percent="60">

<span class="percent"></span>

</span>

</div>

</a>

</li>

<li>

<a href="#">

<div class="task-info clearfix">

<div class="desc pull-left">

<h5>Target Sell</h5>

<p>33% , Deadline 12 June’13</p>

</div>

<span class="notification-pie-chart pull-right" data-percent="90">

<span class="percent"></span>

</span>

</div>

</a>

</li>

 

<li class="external">

<a href="#">See All Tasks</a>

</li>

</ul>

</li>

<!-- settings end -->

<!-- inbox dropdown start-->

<li id="header_inbox_bar" class="dropdown">

<a data-toggle="dropdown" class="dropdown-toggle" href="#">

<i class="fa fa-envelope-o"></i>

<span class="badge bg-important">4</span>

</a>

<ul class="dropdown-menu extended inbox">

<li>

<p class="red">You have 4 Mails</p>

</li>

<li>

<a href="#">

<span class="photo"><img alt="avatar" src="images/avatar-mini.jpg"></span>

<span class="subject">

<span class="from">Jonathan Smith</span>

<span class="time">Just now</span>

</span>

<span class="message">

Hello, this is an example msg.

</span>

</a>

</li>

<li>

<a href="#">

<span class="photo"><img alt="avatar" src="images/avatar-mini-2.jpg"></span>

<span class="subject">

<span class="from">Jane Doe</span>

<span class="time">2 min ago</span>

</span>

<span class="message">

Nice admin template

</span>

</a>

</li>

<li>

<a href="#">

<span class="photo"><img alt="avatar" src="images/avatar-mini-3.jpg"></span>

<span class="subject">

<span class="from">Tasi sam</span>

<span class="time">2 days ago</span>

</span>

<span class="message">

This is an example msg.

</span>

</a>

</li>

<li>

<a href="#">

<span class="photo"><img alt="avatar" src="images/avatar-mini.jpg"></span>

<span class="subject">

<span class="from">Mr. Perfect</span>

<span class="time">2 hour ago</span>

</span>

<span class="message">

Hi there, its a test

</span>

</a>

</li>

<li>

<a href="#">See all messages</a>

</li>

</ul>

</li>

<!-- inbox dropdown end -->

<!-- notification dropdown start-->

<li id="header_notification_bar" class="dropdown">

<a data-toggle="dropdown" class="dropdown-toggle" href="#">

 

<i class="fa fa-bell-o"></i>

<span class="badge bg-warning">3</span>

</a>

<ul class="dropdown-menu extended notification">

<li>

<p>Notifications</p>

</li>

<li>

<div class="alert alert-info clearfix">

<span class="alert-icon"><i class="fa fa-bolt"></i></span>

<div class="noti-info">

<a href="#"> Server #1 overloaded.</a>

</div>

</div>

</li>

<li>

<div class="alert alert-danger clearfix">

<span class="alert-icon"><i class="fa fa-bolt"></i></span>

<div class="noti-info">

<a href="#"> Server #2 overloaded.</a>

</div>

</div>

</li>

<li>

<div class="alert alert-success clearfix">

<span class="alert-icon"><i class="fa fa-bolt"></i></span>

<div class="noti-info">

<a href="#"> Server #3 overloaded.</a>

</div>

</div>

</li>

 

</ul>

</li>

<!-- notification dropdown end -->

</ul>

<!-- notification end -->

</div>

<div class="top-nav clearfix">

<!--search & user info start-->

<ul class="nav pull-right top-menu">

<li>

<input type="text" class="form-control search" placeholder=" Search">

</li>

<!-- user login dropdown start-->

<li class="dropdown"><a href="#"><i class=" fa fa-suitcase"></i>Profile</a>

<ul class="dropdown-menu extended logout">

<li><a href="#"><i class="fa fa-cog"></i> Settings</a></li>

<li><a href="login.html"><i class="fa fa-key"></i> Log Out</a></li>

</ul>

</li>

<!-- user login dropdown end -->

<li>

<div class="toggle-right-box">

<div class="fa fa-bars"></div>

</div>

</li>

</ul>

<!--search & user info end-->

</div>

</header>

<!--header end-->

 

 

<!--sidebar end-->

<!--main content start-->

<section id="main-content">

<section class="wrapper">

<!-- page start-->

 

<div class="row">

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading">

Dados da propriedade

<span class="tools pull-right">

<a href="javascript:;" class="fa fa-chevron-down"></a>

<a href="javascript:;" class="fa fa-cog"></a>

<a href="javascript:;" class="fa fa-times"></a>

</span>

 

 

 

 

 

- <a href="\prefeitura/atualizar_resultado.php?id=<?php echo $row['idfazenda']; ?> "> Atualizar os dados da fazenda</a> </header>

<div class="panel-body">

<table class="table table-hover general-table">

<tbody>

<tr>

<td width="17%"><a href="#">Numero da Fazenda</a></td>

<td width="83%" class="hidden-phone"><?php echo $row['numero']; ?></td>

</tr>

<tr>

<td>

<a href="#">

Proprietario</a>

</td>

<td class="hidden-phone"><?php echo $row['proprietario']; ?></td>

</tr>

<tr>

<td>

<a href="#">

Nome da Fazenda</a>

</td>

<td class="hidden-phone"><?php echo $row['propriedade']; ?></td>

</tr>

<tr>

<td><a href="#">Região que se Encontra</a></td>

<td class="hidden-phone"><?php echo $row['regiao']; ?></td>

</tr>

<tr>

<td>

<a href="#">Distância da Cidade</a></td>

<td class="hidden-phone"><?php echo $row['distancia']; ?></td>

</tr>

 

</tbody>

</table>

</div>

</section>

</div>

</div>

 

<div class="row">

<div class="col-sm-6">

<section class="panel">

<header class="panel-heading">

quantidade de pessoas<span class="tools pull-right">

<a href="javascript:;" class="fa fa-chevron-down"></a>

<a href="javascript:;" class="fa fa-cog"></a>

<a href="javascript:;" class="fa fa-times"></a>

</span>

</header>

<div class="panel-body">

<table class="table">

<tbody>

<tr>

<td width="28%">Crianças</td>

<td width="72%"><?php echo $row['criancas']; ?></td>

</tr>

<tr>

<td>Adultos</td>

<td><?php echo $row['adultos']; ?></td>

</tr>

<tr>

<td>Idosos</td>

<td><?php echo $row['idosos']; ?></td>

</tr>

</tbody>

</table>

</div>

 

</section>

</div>

<div class="col-sm-6">

<section class="panel">

<header class="panel-heading"> Transporte Escolar<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a> </span> </header>

<div class="panel-body">

<table class="table">

<tbody>

<tr>

<td width="28%">Vespertino</td>

<td width="72%"><?php echo $row['vespertino']; ?></td>

</tr>

<tr>

<td>Matutino</td>

<td><?php echo $row['matutino']; ?></td>

</tr>

<tr>

<td>Noturno</td>

<td><?php echo $row['noturno']; ?></td>

</tr>

</tbody>

</table>

</div>

</section>

</div>

</div>

<div class="row">

<div class="col-sm-6">

<section class="panel">

<header class="panel-heading"> culturas cultivadas<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a></span></header>

<div class="panel-body">

<table class="table">

<tbody>

<tr>

<td width="28%">Cultura 1</td>

<td width="72%"><?php echo $row['cultura1']; ?></td>

</tr>

<tr>

<td>Cultura 2</td>

<td><?php echo $row['cultura2']; ?></td>

</tr>

<tr>

<td>Cultura 3</td>

<td><?php echo $row['cultura3']; ?></td>

</tr>

</tbody>

</table>

</div>

</section>

</div>

<div class="col-sm-6">

<section class="panel">

<header class="panel-heading"> Criações e produção de Leite<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a></span></header>

<div class="panel-body">

<table class="table">

<tbody>

<tr>

<td width="28%">Criações 1</td>

<td width="72%"><?php echo $row['criacao1']; ?></td>

</tr>

<tr>

<td>Criações 2</td>

<td><?php echo $row['criacao2']; ?></td>

</tr>

<tr>

<td height="47">Quantidade de Leite </td>

<td><?php echo $row['quantidade']; ?> Litros dia</td>

</tr>

</tbody>

</table>

</div>

</section>

</div>

</div>

<!-- page end-->

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading"> Mais dados</header>

<div class="panel-body">

<table class="table table-hover general-table">

<tbody>

<tr>

<td width="21%">Observação</td>

<td width="79%" class="hidden-phone"><?php echo $row['obs']; ?></td>

</tr>

</tbody>

</table>

</div>

</section>

</div>

 

<div align="center"><a href="\prefeitura/servicos.php?id=<?php echo $row ['idfazenda']?>"> <button type="button" class="btn btn-primary" >Cadastrar Serviço</button> </a></div>

 

 

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading"> Agricultura e meio Ambiente<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a> </span> </header>

<div class="panel-body">

<div class="adv-table">

<table class="display table table-bordered table-striped" id="dynamic-table">

<thead>

<tr>

<?php

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos

 

ON fazendas.idfazenda=servicos.idfazenda

 

and servicos.idcategoria=1

 

group by servicos.idcategoria");

 

 

 

$sql = $db->Execute($row);

 

while($row1 = $query->FetchRow())

 

{

 

 

 

?>

<th width="13%">Data</th>

<th width="87%">Serviços</th>

</tr>

</thead>

<tbody>

<tr class="gradeX">

<td><?php echo $row ['data']?></td>

<td><?php echo $row ['servicos']?></td>

<?php } ?>

</tr>

 

</tbody>

<tfoot>

</tfoot>

</table>

</div>

</div>

</section>

</div>

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading"> estradas<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a></span></header>

<div class="panel-body">

<div class="adv-table">

<table class="display table table-bordered table-striped" id="dynamic-table2">

<thead>

<tr><?php

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos

 

ON fazendas.idfazenda=servicos.idfazenda

 

and servicos.idcategoria=2

 

group by servicos.idcategoria");

 

 

 

$sql = $db->Execute($row);

 

while($row1 = $query->FetchRow())

 

{

 

 

 

?>

<th width="13%">Data</th>

<th width="87%">Serviço Prestado</th>

</tr>

</thead>

<tbody>

<tr class="gradeX">

<td><?php echo $row ['data']?></td>

<td><?php echo $row ['servicos']?></td>

<?php } ?>

</tr>

</tbody>

<tfoot>

</tfoot>

</table>

</div>

</div>

</section>

</div>

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading"> Saude<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a></span></header>

<div class="panel-body">

<div class="adv-table">

<table class="display table table-bordered table-striped" id="dynamic-table3">

<thead>

<tr><?php

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos

 

ON fazendas.idfazenda=servicos.idfazenda

 

and servicos.idcategoria=3

 

group by servicos.idcategoria");

 

 

 

$sql = $db->Execute($row);

 

while($row1 = $query->FetchRow())

 

{

 

 

 

?>

<th width="13%">Data</th>

<th width="87%">Serviço Prestado</th>

</tr>

</thead>

<tbody>

<tr class="gradeX">

<td><?php echo $row ['data']?></td>

<td><?php echo $row ['servicos']?></td>

<?php } ?>

</tr>

</tbody>

<tfoot>

</tfoot>

</table>

</div>

</div>

</section>

</div>

<div class="col-sm-12">

<section class="panel">

<header class="panel-heading"> obras<span class="tools pull-right"> <a href="javascript:;" class="fa fa-chevron-down"></a> <a href="javascript:;" class="fa fa-cog"></a> <a href="javascript:;" class="fa fa-times"></a></span></header>

<div class="panel-body">

<div class="adv-table">

<table class="display table table-bordered table-striped" id="dynamic-table4">

<thead>

<tr><?php

 

$sql = ("SELECT * FROM fazendas LEFT JOIN servicos

 

ON fazendas.idfazenda=servicos.idfazenda

 

and servicos.idcategoria=4

 

group by servicos.idcategoria");

 

 

 

$sql = $db->Execute($row);

 

while($row1 = $query->FetchRow())

 

{

 

 

 

?>

<th width="13%">Data</th>

<th width="87%">Serviço Prestado</th>

</tr>

</thead>

<tbody>

<tr class="gradeX">

<td><?php echo $row ['data']?></td>

<td><?php echo $row ['servicos']?></td>

<?php } ?>

</tr>

</tbody>

<tfoot>

</tfoot>

</table>

</div>

</div>

</section>

</div>

</section>

</section>

<!--main content end-->

<!--right sidebar start--><!--right sidebar end-->

 

</section>

 

<!-- Placed js at the end of the document so the pages load faster -->

 

<!--Core js-->

<script src="js/lib/jquery.js"></script>

<script src="bs3/js/bootstrap.min.js"></script>

<script class="include" type="text/javascript" src="js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>

<script src="js/scrollTo/jquery.scrollTo.min.js"></script>

<script src="js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>

<!--Easy Pie Chart-->

<script src="assets/easypiechart/jquery.easypiechart.js"></script>

<!--Sparkline Chart-->

<script src="assets/sparkline/jquery.sparkline.js"></script>

<!--jQuery Flot Chart-->

<script src="assets/flot-chart/jquery.flot.js"></script>

<script src="assets/flot-chart/jquery.flot.tooltip.min.js"></script>

<script src="assets/flot-chart/jquery.flot.resize.js"></script>

<script src="assets/flot-chart/jquery.flot.pie.resize.js"></script>

 

 

<!--common script init for all pages-->

<script src="js/scripts.js"></script>

 

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.