Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
ai galera! bkna !
estou com um formulário que possui os seguintes campos
<form id="form1" method="get" action="busca.php">
<label>de
<input type="text" name="dt1" id="dt1" />
ao</label>
<label>
<input type="text" name="dt2" id="dt2" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
</form>
minha duvida é o seguinte.
gostaria de pesquisa no meu banco de dados, mas especificamente na tabela GTA no campo data_emissao
a pesquisa fizesse um intervalo. por ex.: gostaria de pesquisa no campo data_emissao, datas entre o dia xx/xx/xxx ao dia yy/yy/yy
e mostrasse so esse perio da data X ao Y . entenderam ? e exiba essa busca
grato.
cfmjunior
quem quiser testar tmbm
<?php require_once('../Connections/diagro.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$dt1_Recordset1 = "-1";
if (isset($_GET['dt1'])) {
$dt1_Recordset1 = $_GET['dt1'];
}
$dt2_Recordset1 = "-1";
if (isset($_GET['dt2'])) {
$dt2_Recordset1 = $_GET['dt2'];
}
mysql_select_db($database_diagro, $diagro);
$query_Recordset1 = sprintf("SELECT * FROM gta WHERE gta.data_emissao BETWEEN %s and %s", GetSQLValueString("%" . $dt1_Recordset1 . "%", "date"),GetSQLValueString("%" . $dt2_Recordset1 . "%", "date"));
$Recordset1 = mysql_query($query_Recordset1, $diagro) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
/*
<?php { ?>
<table>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); {?>
<tr><td><? $row_Recordset1[0]?></td><? $row_Recordset1[1]?><td><? $row_Recordset1[2]?></td><td><? $row_Recordset1[3]?></td></tr>
<? } ?>
</table>
*/
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" method="get" action="busca.php">
<label>de
<input type="text" name="dt1" id="dt1" />
ao</label>
<label>
<input type="text" name="dt2" id="dt2" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
</form>
</body>
</html>
sql ## gta ##
-- phpMyAdmin SQL Dump
-- version 2.11.7
--
-- Servidor: localhost
-- Tempo de Geração: Abr 01, 2011 as 09:27 AM
-- Versão do Servidor: 5.0.51
-- Versão do PHP: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Banco de Dados: gta
--
-- --------------------------------------------------------
--
-- Estrutura da tabela gta
--
CREATE TABLE IF NOT EXISTS `gta` (
`id_gta` int(100) NOT NULL auto_increment,
`numero_gta` char(50) default NULL,
`serie_gta` varchar(1) default NULL,
`data_emissao` date default NULL,
`tipo_de_transito` varchar(20) default NULL,
`finalidade` varchar(20) default NULL,
`especie` varchar(20) default NULL,
`total_machos` char(50) default NULL,
`total_femeas` char(50) default NULL,
`total_animais` char(50) default NULL,
`cod_municipio` char(10) default NULL,
`municipio` varchar(40) default NULL,
`cpf_produtor` varchar(14) default NULL,
`cnpj_produtor` varchar(18) default NULL,
`nome_produtor` varchar(255) default NULL,
`incra_propriedade` varchar(255) default NULL,
`nome_propriedade_origem` varchar(255) default NULL,
`uf_destino` varchar(255) default NULL,
`cod_munic_destino` varchar(255) default NULL,
`municipio_destino` varchar(255) default NULL,
`cpf_destino` varchar(14) default NULL,
`cnpj_destino` varchar(18) default NULL,
`nome_destinatario` varchar(255) default NULL,
`nome_propriedade_destino` varchar(255) default NULL,
`nome_emitente` varchar(255) default NULL,
`nomeuser` varchar(50) default NULL,
`data_cadastro` date default NULL,
PRIMARY KEY (`id_gta`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;
--
-- Extraindo dados da tabela gta
--
INSERT INTO gta (id_gta, numero_gta, serie_gta, data_emissao, tipo_de_transito, finalidade, especie, total_machos, total_femeas, total_animais, cod_municipio, municipio, cpf_produtor, cnpj_produtor, nome_produtor, incra_propriedade, nome_propriedade_origem, uf_destino, cod_munic_destino, municipio_destino, cpf_destino, cnpj_destino, nome_destinatario, nome_propriedade_destino, nome_emitente, nomeuser, data_cadastro) VALUES
(21, '122', NULL, '2010-06-12', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(22, '123', NULL, '2010-06-13', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(23, NULL, NULL, '2010-06-14', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(24, NULL, NULL, '2010-06-15', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(25, NULL, NULL, '2010-02-22', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(26, NULL, NULL, '2010-02-22', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(27, NULL, NULL, '2003-02-01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30'),
(28, NULL, NULL, '2004-02-01', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-03-30');
Carregando comentários...