Bom dia Pessoal! Tudo Bem?
Estou com o seguinte problema, estou realizando a pesquisa no banco de dados com PHP, porem os dados abrem como se fosse em outra pagina.
Porem eu gostaria de ter o mesmo resultado deste formulário que criei:
consulta_php
<?php // Verifica se foi feita alguma busca // Caso contrario, redireciona o visitante pra home if (!isset($_GET['consulta'])) { exit; } // Conecte-se ao MySQL antes desse ponto include ('/conectar_php.php'); // Salva o que foi buscado em uma variável $busca = mysql_real_escape_string($_GET['consulta']); // ============================================ // conecta ao banco de dados $con = mysql_pconnect($host, $user, $pass) or trigger_error(mysql_error(),E_USER_ERROR); // seleciona a base de dados em que vamos trabalhar mysql_select_db($db, $con); // cria a instrução SQL que vai selecionar os dados $query = ("SELECT * FROM `produtos` WHERE ((`cod_item` LIKE '%".$busca."%')) ORDER BY `cod_item` ASC"); // executa a query $dados = mysql_query($query, $con) or die(mysql_error()); // transforma os dados em um array $linha = mysql_fetch_assoc($dados); // calcula quantos dados retornaram $total = mysql_num_rows($dados); ?> <?php // se o número de resultados for maior que zero, mostra os dados if($total > 0) { // inicia o loop que vai mostrar todos os dados do { ?> <tr>
<td><?=$linha['cod_item']?></td>
<td><?=$linha['descricao']?></td>
<td><?=$linha['linha']?></td>
<td><?=$linha['percentual_desc']?></td>
<td><?=$linha['preco_final']?></td>
</tr>
<?php
// finaliza o loop que vai mostrar os dados
}while($linha = mysql_fetch_assoc($dados));
// fim do if
}
?>
form1.php
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin - Bootstrap Admin Template</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[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.4.2/respond.min.js"></script>
<![endif]-->
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-dark bg-inverse navbar-fixed-top">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button class="navbar-toggler hidden-sm-up pull-sm-right" type="button" data-toggle="collapse" data-target=".navbar-ex1-collapse">
☰
</button>
<a class="navbar-brand" href="index.html">SB Admin BS 4</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-nav top-nav navbar-right pull-xs-right">
<li class="dropdown nav-item active">
<!-- <div class="dropdown"> -->
<a class="nav-link dropdown-toggle" href="javascript:;" id="dropdownMenu4" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-envelope"></i> <b class="caret"></b><span class="sr-only">(current)</span></a>
<ul class="dropdown-menu message-dropdown">
<li class="dropdown-item message-preview">
<a href="javascript:;">
<div class="media">
<span class="media-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong>John Smith</strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="dropdown-item message-preview">
<a href="javascript:;">
<div class="media">
<span class="media-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong>John Smith</strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="dropdown-item message-preview">
<a href="javascript:;">
<div class="media">
<span class="media-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong>John Smith</strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="dropdown-item message-footer">
<a href="javascript:;">Read All New Messages</a>
</li>
</ul>
<!-- </div> -->
</li>
<li class="dropdown nav-item">
<!-- <div class="dropdown"> -->
<a href="javascript:;" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-bell"></i> <b class="caret"></b><span class="sr-only">(current)</span></a>
<ul class="dropdown-menu alert-dropdown">
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-default"> Alert Badge</span></a>
</li>
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-primary"> Alert Badge</span></a>
</li>
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-success">Alert Badge</span></a>
</li>
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-info"> Alert Badge</span></a>
</li>
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-warning"> Alert Badge</span></a>
</li>
<li class="dropdown-item">
<a href="javascript:;">Alert Name <span class="label label-danger"> Alert Badge</span></a>
</li>
<li class="dropdown-divider"></li>
<li class="dropdown-item">
<a href="javascript:;">View All</a>
</li>
</ul>
<!-- </div> -->
</li>
<li class="dropdown nav-item">
<a href="javascript:;" class="nav-link dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> John Smith <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-item">
<a href="javascript:;"><i class="fa fa-fw fa-user"></i> Profile</a>
</li>
<li class="dropdown-item">
<a href="javascript:;"><i class="fa fa-fw fa-envelope"></i> Inbox</a>
</li>
<li class="dropdown-item">
<a href="javascript:;"><i class="fa fa-fw fa-gear"></i> Settings</a>
</li>
<li class="divider"></li>
<li class="dropdown-item">
<a href="javascript:;"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-toggleable-sm navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav list-group">
<li class="list-group-item">
<a href="index.html"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>
</li>
<li class="list-group-item">
<a href="charts.html"><i class="fa fa-fw fa-bar-chart-o"></i> Charts</a>
</li>
<li class="list-group-item">
<a href="tables1.php"><i class="fa fa-fw fa-table"></i> Produtos</a>
</li>
<li class="list-group-item">
<a href="forms1.php"><i class="fa fa-fw fa-edit"></i> Pesquisa</a>
</li>
<li class="list-group-item">
<a href="bootstrap-elements.html"><i class="fa fa-fw fa-desktop"></i> Bootstrap Elements</a>
</li>
<li class="list-group-item">
<a href="bootstrap-grid.html"><i class="fa fa-fw fa-wrench"></i> Bootstrap Grid</a>
</li>
<li class="list-group-item">
<a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-arrows-v"></i> Dropdown <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="demo" class="list-group collapse">
<li class="list-group-item">
<a href="javascript:;">Dropdown Item</a>
</li>
<li class="list-group-item">
<a href="javascript:;">Dropdown Item</a>
</li>
</ul>
</li>
<li class="list-group-item">
<a href="blank-page.html"><i class="fa fa-fw fa-file"></i> Blank Page</a>
</li>
<li class="list-group-item">
<a href="index-rtl.html"><i class="fa fa-fw fa-dashboard"></i> RTL Dashboard</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
PESQUISA
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> <a href="index.html">Dashboard</a>
</li>
<li class="active">
<i class="fa fa-edit"></i> PESQUISA PRODUTOS
</li>
</ol>
</div>
</div>
<!-- /.row = DIV Linha-->
<form role="form" name="frmBusca" method="get" action="./app/consulta_php.php">
<div class="row">
<div class="col-lg-4">
<div class="form-group input-group">
<input type="text" class="form-control" placeholder="Pesquise aqui! ex.: 1FR31634" id="consulta" name="consulta">
<span class="input-group-btn"><button class="btn btn-secondary" type="button" type="submit" value="Buscar"><i class="fa fa-search"></i></button></span>
</div>
</div>
</form>
<!-- /.row -->
<!-- /.container-fluid -->
<div class="col-xl-6 col-xl-12">
<h2>Lista Produtos</h2>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>CÓDIGO</th>
<th>DESCRIÇÃO</th>
<th>CENTO / PEÇA</th>
<th>DESCONTO</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody>
<?php
// definições de host, database, usuário e senha
include (’./app/conectar_php.php’);
// seleciona a base de dados em que vamos trabalhar
mysql_select_db($db, $con);
// cria a instrução SQL que vai selecionar os dados
$query = sprintf(“SELECT cod_item, cod_item, descricao, linha, super_linha, preco_bruto, percentual_desc, preco_final, id FROM produtos where id <=1”);
// executa a query
$dados = mysql_query($query, $con) or die(mysql_error());
// transforma os dados em um array
$linha = mysql_fetch_assoc($dados);
// calcula quantos dados retornaram
$total = mysql_num_rows($dados);
?>
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>