PAGINA DE PESQUISA, DUVIDA SOBRE VARIAVEIS

Enviada por Rodrigo Gaiotto 
Rodrigo Gaiotto
PAGINA DE PESQUISA, DUVIDA SOBRE VARIAVEIS
14 de August de 2017 às 06:50PM
Boa noite pessoal,

Tenho pouca experiencia com desenvolvimento Web (estou curtindo demais PHP) e estou criando uma aplicação simples que apenas mostra tabelas na tela.
Estou criando uma pagina de Busca e para o SELECT preciso de 4 variaveis:

$system - que é o nome do sistema
$location - que é a localização
$post_at - que é a data inicial
$post_at_todate - que é a data final

Os DropDowns estão populando com sucesso pegando as informações do BANCO DE DADOS, e quando testei a busca por DATA sem os menus DropDown funcionou com sucesso.

PROBLEMA: não estou conseguindo gravar as opções selecionadas nos menus em variaveis para usar no SELECT para realizar as buscas dentro do Banco de Dados.
Quando Submeto PERCO o que foi gravado na variavel anterior.




CÓDIGO (ADMITO QUE TEM GAMBIARRA PRA COMPENSAR A MINHA FALTA DE CONHECIMENTO):




<?php

$location="";
$locationf="";
$system="";
$systemf="";

$conn = mysqli_connect('localhost', 'root', 'test', 'SRSBASE')
or die ('Cannot connect to db');

$result = $conn->query("select distinct SUB_ACCOUNT from SRSLOAD");

if(isset($_POST["selec"]["account"])) {
$location = $_POST["selec"]["account"];
$locationf = $location;
$locationf = sprintf('%s', $locationf);
}

echo "Location: $locationf";

$conn2 = mysqli_connect('localhost', 'root', 'test', 'SRSBASE')
or die ('Cannot connect to db');


$result2 = $conn2->query("select distinct SYSTEMNAME from SRSLOAD where SUB_ACCOUNT='$locationf'");

if(isset($_POST["selec"]["system"])) {
$system = $_POST["selec"]["system"];
$systemf = $system;
}

echo "System: $systemf";

$post_at = "";
$post_at_to_date = "";
$post_at_todate = "";

$queryCondition = "";
if(!empty($_POST["search"]["post_at"])) {
$post_at = $_POST["search"]["post_at"];
list($fiy,$fim,$fid) = explode("-",$post_at);

$post_at_todate = date('YY-mm-dd');
if(!empty($_POST["search"]["post_at_to_date"])) {
$post_at_to_date = $_POST["search"]["post_at_to_date"];
list($tiy,$tim,$tid) = explode("-",$_POST["search"]["post_at_to_date"]);
$post_at_todate = "$tiy-$tim-$tid";

//TESTING SELECTED TARGETS
//echo $post_at;
//echo "/";
//echo $post_at_todate;
}


//$queryCondition .= "WHERE RDATE BETWEEN '$fiy-$fim-$fid' AND '" . $post_at_todate . "'";
$queryCondition .= "WHERE RDATE BETWEEN '$post_at' AND '" . $post_at_todate . "'";
}



//$sql = "SELECT * from SRSLOAD " . $queryCondition . " ORDER BY post_at desc";
//$sql = "select * from SRSLOAD where rdate between '$post_at' AND $post_at_todate;"

$sql = sprintf("SELECT * FROM SRSLOAD WHERE RDATE BETWEEN '%s' AND '%s' AND SYSTEMNAME='%s' AND SUB_ACCOUNT='%s'", $post_at, $post_at_todate, $systemf, $locationf);

$result3 = mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Storage Report System - Search</title>
<script src="jquery-1.9.1.js"></script>
<link rel="stylesheet" href="jquery-ui-1.11.4.css">

<style>
.table-content{border-top:#CCCCCC 4px solid; width:50%;}
.table-content th {padding:5px 20px; background: #F0F0F0;vertical-align:top;}
.table-content td {padding:5px 20px; border-bottom: #F0F0F0 1px solid;vertical-align:top;}
</style>
</head>
<body>

<h2 style='font-family:arial'>Storage Report System - Search</h2>

<form name='sname' id='sname' action='' method='POST'>
<select id='select' name="selec[account]" value="<?php echo $location; ?>" >
<option value='-1'>--Select the Location--</option>

<?php
while ($row = $result->fetch_assoc()) {
unset($sub_acc);
$sub_acc = $row['SUB_ACCOUNT'];
echo '<option value="'.$sub_acc.'">'.$sub_acc.'</option>';
}
?>

</select>
<input type='submit' value='Validate' />
</form>

<form name='sname' id='sname' action='' method='POST' >
<select id='system' name="selec[system]" value="<?php echo $system; ?>" >

<option value='-1'>--Select the System--</option>
<?php while ($row2 = $result2->fetch_assoc()) {

unset($syst);
$syst = $row2['SYSTEMNAME'];
echo '<option value="'.$syst.'">'.$syst.'</option>';

}
?>
</select>
<input type='submit' value='Validate' />
</form>

<div class="demo-content">
<form name="frmSearch" method="post" action="">
<p class="search_input">
<input type="text" placeholder="From Date" id="post_at" name="search[post_at]" value="<?php echo $post_at; ?>" class="input-control" />
<input type="text" placeholder="To Date" id="post_at_to_date" name="search[post_at_to_date]" style="margin-left:10px" value="<?php echo $post_at_to_date; ?>" class="input-control" />
<input type="submit" name="go" value="Search" >
</p>
<?php if(!empty($result3)) { ?>
<table class="table-content">
<thead>
<tr>
<th width="30%"><span>SYSTEM NAME</span></th>
<th width="50%"><span>DATE</span></th>
<th width="20%"><span>HSM</span></th>
</tr>
</thead>
<tbody>
<?php
while($row3 = mysqli_fetch_array($result3)) {
?>
<tr>
<td><?php echo $row["SYSTEMNAME"]; ?></td>
<td><?php echo $row["RDATE"]; ?></td>
<td><?php echo $row["HSM_MCDS"]; ?></td>

</tr>
<?php
}
?>
<tbody>
</table>
<?php } ?>
</form>
</div>
<script src="jquery-ui-1.10.3.js"></script>
<script>
$.datepicker.setDefaults({
showOn: "button",
buttonImage: "datepicker.png",
buttonText: "Date Picker",
buttonImageOnly: true,
dateFormat: 'yy-mm-dd'
});
$(function() {
$("#post_at").datepicker();
$("#post_at_to_date").datepicker();
});
</script>
</body></html>
José Ângelo Lefundes Coelho
Re: PAGINA DE PESQUISA, DUVIDA SOBRE VARIAVEIS
15 de August de 2017 às 08:04PM
chama no skype ai: jose.angelo.lefundes.coelho
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.