vaigran 0 Denunciar post Postado Novembro 24, 2015 Pessoal, boa tarde. Estou querendo fazer uma pesquisa onde o resultado é o número de solicitações que cada usuário fez em um determinado período. Segue as tabelas do BD: CREATE TABLE IF NOT EXISTS `solicitacao` ( `idsolicitacao` int(11) NOT NULL AUTO_INCREMENT, `idusuariosol` int(11) NOT NULL, `idcidadaosol` int(11) NOT NULL, `idcategoriasol` int(11) NOT NULL, `datasol` datetime NOT NULL, `titulosol` varchar(100) NOT NULL, `descricaosol` longtext NOT NULL, `enderecosol` varchar(255) NOT NULL, `bairrosol` varchar(100) NOT NULL, `cidadesol` varchar(100) NOT NULL, `cepsol` varchar(20) NOT NULL, `protocolosol` varchar(20) DEFAULT NULL, `status` varchar(50) NOT NULL, `oficiosol` int(11) DEFAULT NULL, `infosol` longtext, PRIMARY KEY (`idsolicitacao`,`idusuariosol`,`idcidadaosol`,`idcategoriasol`), KEY `fk_solicitacao_usuario_idx` (`idusuariosol`), KEY `fk_solicitacao_cidadao1_idx` (`idcidadaosol`), KEY `fk_solicitacao_categoria1_idx` (`idcategoriasol`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; CREATE TABLE IF NOT EXISTS `usuario` ( `idusuario` int(11) NOT NULL AUTO_INCREMENT, `emailusu` varchar(45) NOT NULL, `senhausu` char(40) NOT NULL, `nomeusu` varchar(45) NOT NULL, `tipousu` varchar(45) NOT NULL, `statususu` varchar(10) NOT NULL, PRIMARY KEY (`idusuario`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; O trecho do arquivo relatorio.php: <form role="form" method="POST" action="<?= do_action('relatorio_usuarios'); ?>"> <div class="form-group"> <label for="datainicial">De:</label> <input type="date" name="datainicial" id="datainicial"> </div> <div class="form-group"> <label for="datafinal">Até:</label> <input type="date" name="datafinal" id="datafinal"> </div> <div class="form-group"> <button type="submit" name="formru" class="btn btn-primary btn-lg">Ok</button> </div> </form> E o arquivo relatorio_usuarios.php: if( isset($_POST['formru']) ) { $datainicial = date('datainicial'); $datafinal = date('datafinal'); } ?> <h1 class="page-header">Resultado:</h1> <div class="table-responsive"> <table class="table table-striped wcms-table"> <thead> <tr> <th>Nome do usuário</th> <th>Número de solicitações</th> </tr> </thead> <tbody> <?php $conn = getConnection(); $stmt = $conn->query( "SELECT * FROM solicitacao WHERE datasol BETWEEN '$datainicial' AND '$datafinal'" ); $data = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($data as $dat) : ?> <tr> <td><?= get_nome_cidadao($dat); ?></td> <td><?= wcms_db_select('solicitacao', ['count(idsolicitacao) as total'], ['idusuariosol' => $dat->idusuariosol]) [0]->total; ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> A intenção é exibir uma tabela com o nome do usuário e ao lado o número de solicitações que ele já fez com o período selecionado no form. Essas funções que criei get_nome_cidadao() e wcms_db_select() já funcionam em outros lugares, então o erro não está nelas. Atualmente, fica aparecendo a tabela vazia, dei um var_dump e retorna 0. Alguém tem alguma ideia de como posso fazer essa busca? Compartilhar este post Link para o post Compartilhar em outros sites