Ir para conteúdo

POWERED BY:

Arquivado

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

Remazela

PHP com SELECT

Recommended Posts

Caros amigos

 

Desculpa por recorrer aos amigos.

 

Estou desenvolvendo uma Rotina onde deixo alguns Anúncios Pendentes para serem Aprovados (após a confirmação do pagamento), infelizmente quando quero buscar um Código do Usuário aleatoriamente, a rotina só busca do Último para o Primeiro.

 

Observação: já fiz todas as alterações possíveis dos meus conhecimento, mas não tive êxito.

 

Tentei escrever o SELECT conforme abaixo, mas não acha os dados do usuário.

$sql_pegaAtivos = 'SELECT * FROM imoveis WHERE imovelId = :imovelId

AND imovelStatus = :imovelStatus
AND imovelTermino >= :data ORDER BY imovelTermino ASC';

 

 

O Sistema chama 1º a Rotina pendentes.php que após escolher qual usuário irá aprovar, chama a pendentes_single.php.

 

 

Código Fonte da pendentes.php:

<div id="content">

<?php include_once("menu.php");?>     

   <div id="content_conteudo">
   
<?php include_once("sistema/carregando.php");?>
   
<table width="100%" border="0" cellspacing="3" cellpadding="0">
  <tr style="background:#666; color:#FFF">
    <td align="center">Cliente Id:</td>
    <td align="center">Imóvel Id:</td>
    <td align="center">Cadastro em:</td>
    <td align="center">Executar:</td>
  </tr>
  
 <?php

 $data = date('Y-m-d H:m:s');
 $imovelStatus = 'pendente';

 $sql_pegaAtivos = 'SELECT * FROM imoveis WHERE imovelStatus = :imovelStatus
                    AND imovelTermino >= :data ORDER BY imovelTermino ASC';

 try{
   $query_pegaAtivos = $conecta->prepare($sql_pegaAtivos);
   $query_pegaAtivos->bindValue(':imovelStatus',$imovelStatus,PDO::PARAM_STR);
   $query_pegaAtivos->bindValue(':data',$data,PDO::PARAM_STR);  
   $query_pegaAtivos->execute();
  
   $resultado_pegaAtivos = $query_pegaAtivos->fetchAll(PDO::FETCH_ASSOC);
   
   }catch(PDOexception $error_pegaAtivos){
        echo 'Erro ao pegar ativos';
   }
   
   foreach($resultado_pegaAtivos as $resAtivos){
           $anuncioCliente = $resAtivos['clienteId'];
           $anuncioId      = $resAtivos['imovelId'];
           $anuncioTitulo  = $resAtivos['imovelTitulo'];
           $anuncioInicio  = $resAtivos['imovelCadastro'];
           $anuncioFinal   = $resAtivos['imovelTermino'];
           $anuncioVisitas = $resAtivos['imovelVisitas'];

         //Código para mudar as linhas da Tabela autoincremento.
         $i++;
         if($i % 2 == 0){
           //Cor para toda vez que a linha for par
           $cor = 'style="background: #F5FFFA"';
         }else{
           //Cor para toda vez que a linha for impar
           $cor = 'style="background: #B4EEB4;"';
         }
           
    
        //Transformar data hoje em segundos
        $dataHoje    = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
                
        //Transformar data fim em segundos
        $dataFim     = mktime(0, 0, 0, date('m', strtotime($anuncioFinal)), date('d', strtotime($anuncioFinal)), date('Y', strtotime($anuncioFinal)));
        
        //Calcular quantos dias faltam para terminar prazo anuncio
        $executaData = $dataFim - $dataHoje;
                
        //FLOOR arredondar dias
        //(60=seg * 60=hrs * 24=equiv. 1 dia)
        $faltamDias  = floor($executaData/(60*60*24)); 
 
 ?> 
  
  <tr <?php echo $cor;?>>
    <td align="center"><?php echo $anuncioCliente ;?></td>
    <td align="center"><?php echo $anuncioId ;?></td>
    <td align="center"><?php echo date('d/m/y',strtotime($anuncioInicio));?></td>
    <td align="center"><a href="painel.php?exe=admin-imoveis/pendentes_single&anuncio=<?php echo $anuncioId;?>">Moderar Anúncio</a></td>
  </tr>
  
  <?php

   } //Fechar o 1.Foreach
  
  ?>
 
</table>
   </div><!--conteudo-->

</div><!--contet-->

Código Fonte da pendentes_single.php:

<div id="content">

<?php include_once("menu.php");?>     

   <div id="content_conteudo">
   
   
<?php include_once("sistema/carregando.php");?>

<?php 

if(isset($_POST['executar']) && $_POST['executar'] == 'Aprovar Anúncio'){

$editTitulo = $_POST['editTitulo'];

$editNegocio = $_POST['editNegocio'];
//Validar Campos Radio
  if($editNegocio == ''){
	$editNegocio = $_POST['editNegocioOk'];
    }else{
	$editNegocio = $_POST['editNegocio'];
  }

 $editTipo = $_POST['editTipo'];
 //Validar Campos Radio
	if($editTipo == ''){
	   $editTipo = $_POST['editTipoOk'];
	   }else{
	   $editTipo = $_POST['editTipo'];
	}

$editValor         = $_POST['editValor'];
$editDesc          = $_POST['editDesc'];
$editComodos       = $_POST['editComodos'];
$editSuites        = $_POST['editSuites'];
$editBanheiros     = $_POST['editBanheiros'];
$editSalas         = $_POST['editSalas'];
$editChurrasqueira = $_POST['editChurrasqueira'];
$editGaragem       = $_POST['editGaragem'];
$editServico       = $_POST['editServico'];
$editPiscina       = $_POST['editPiscina'];
$editFacilidades   = $_POST['editFacilidades'];
$editRua           = $_POST['editRua'];
$editNumero        = $_POST['editNumero'];
$editBairro        = $_POST['editBairro'];
$editProximo       = $_POST['editProximo'];

$editImovelId = $_POST['editId'];
                   
$editImovelStatus = 'processando';

$edit_imoveis = 'UPDATE imoveis SET imovelTitulo = :imovelTitulo, imovelNegocio = :imovelNegocio, imovelTipo = :imovelTipo, 
                 imovelValor = :imovelValor, imovelDescricao = :imovelDescricao, imovelComodos = :imovelComodos, imovelSuites = :imovelSuites,
				 imovelBanheiros = :imovelBanheiros, imovelSalas = :imovelSalas, imovelChurrasqueira = :imovelChurrasqueira,
				 imovelGaragem = :imovelGaragem, imovelServico = :imovelServico, imovelPiscina = :imovelPiscina, imovelFacilidades = :imovelFacilidades,
				 imovelRua = :imovelRua, imovelNumero = :imovelNumero, imovelBairro = :imovelBairro, imovelProximo = :imovelProximo,
				 imovelStatus = :imovelStatus WHERE imovelId = :imovelId';
				 
try{
	$query_imovel = $conecta->prepare($edit_imoveis);
	$query_imovel->bindValue(':imovelTitulo',$editTitulo,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelNegocio',$editNegocio,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelTipo',$editTipo,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelValor',$editValor,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelDescricao',$editDesc,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelComodos',$editComodos,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelSuites',$editSuites,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelBanheiros',$editBanheiros,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelSalas',$editSalas,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelChurrasqueira',$editChurrasqueira,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelGaragem',$editGaragem,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelServico',$editServico,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelPiscina',$editPiscina,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelFacilidades',$editFacilidades,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelRua',$editRua,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelNumero',$editNumero,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelBairro',$editBairro,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelProximo',$editProximo,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelStatus',$editImovelStatus,PDO::PARAM_STR);
	$query_imovel->bindValue(':imovelId',$editId,PDO::PARAM_STR);
	$query_imovel->execute();
	
	echo '<div class="ok">Imóvel Liberado</div>';

	//Redirecionando para Caixa de Enrada do Cliente
	echo '<meta http-equiv="refresh" content="1, URL=painel.php?exe=admin-imoveis/pendentes" />';

		}catch(PDOexception $error_editImovel){
		echo 'Erro ao aprovar o imóvel '.$error_editImovel->getMessage();
		}

}
?> 


<?php

  $data = date('Y-m-d H:m:s');
  $imovelStatus = 'pendente';

 $sql_pegaAtivos = 'SELECT * FROM imoveis WHERE imovelStatus = :imovelStatus
                    AND imovelTermino >= :data ORDER BY imovelTermino ASC';

 try{
   $query_pegaAtivos = $conecta->prepare($sql_pegaAtivos);
   $query_pegaAtivos->bindValue(':imovelStatus',$imovelStatus,PDO::PARAM_STR);
   $query_pegaAtivos->bindValue(':data',$data,PDO::PARAM_STR);  
   $query_pegaAtivos->execute();

    $resultado_pegaAtivos = $query_pegaAtivos->fetchAll(PDO::FETCH_ASSOC);
	
	 
	 }catch(PDOexception $error_pegaAtivos){
        echo 'Erro ao pegar ativos';
	 }
	 
	 foreach($resultado_pegaAtivos as $resAtivos){
		 $editCliente     = $resAtivos['clienteId'];
		 $editId          = $resAtivos['imovelId'];
		 $editTitulo      = $resAtivos['imovelTitulo'];
		 $editInicio      = $resAtivos['imovelCadastro'];
		 $editFinal       = $resAtivos['imovelTermino'];
		 $editVisitas     = $resAtivos['imovelVisitas'];
		 $editNegocio     = $resAtivos['imovelNegocio'];
		 $editTipo        = $resAtivos['imovelTipo'];
		 $editThumb       = $resAtivos['imovelThumb'];
		 
		 $editValor       = $resAtivos['imovelValor'];
		 $editDesc        = $resAtivos['imovelDescricao'];
		 $editComodos     = $resAtivos['imovelComodos'];
		 
		 $editSuites           = $resAtivos['imovelSuites'];
		 $editBanheiros        = $resAtivos['imovelBanheiros'];
		 $editSalas            = $resAtivos['imovelSalas'];
		 
		 $editChurrasqueira    = $resAtivos['imovelChurrasqueira'];
		 $editGaragem          = $resAtivos['imovelGaragem'];
		 $editServico          = $resAtivos['imovelServico'];
		 $editPiscina          = $resAtivos['imovelPiscina']; 
		 
		 $editRua               = $resAtivos['imovelRua'];
		 $editNumero            = $resAtivos['imovelNumero'];
		 $editBairro            = $resAtivos['imovelBairro'];
		 $editProximo           = $resAtivos['imovelProximo'];
		 $editFacilidades       = $resAtivos['imovelFacilidades'];
		
		$dataHoje = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$dataFim = mktime(0,0,0,date('m',strtotime($anuncioFinal)),date('d',strtotime($anuncioFinal)), date('Y',strtotime($anuncioFinal)));
		$executaData = $dataFim - $dataHoje;
		$faltamDias = floor($executaData/(60*60*24));
		 
		 
	 }
 
 ?> 
 
<h3 class="titulo">Id do Imóvel: <strong><?php echo $editId;?></strong> | id do cliente: <strong><?php echo $editCliente;?></strong> | Cadastro em: <strong><?php echo date('d/m/Y H:m',strtotime($editInicio));?>h</strong></h3>
<span class="exibir"><img src="../midias/<?php echo $editThumb;?>" alt="" width="100"/></span> 

    <form name="anuncios_aprovar" action="" enctype="multipart/form-data" method="post">
      
    
      <label>
        <span>Titulo do anúncio:</span>
        <input type="text" name="editTitulo" value="<?php echo $editTitulo;?>" size="110" />
      </label>
      <p>
      <label>
        <span>Negocio: <strong style="color: #363636;"><?php echo $editNegocio;?></strong></span>
      </label>
          <input type="radio" name="editNegocio" value="alugar" /> Alugar
          <input type="radio" name="editNegocio" value="vender" /> Vender
          <input type="hidden" name="editNegocioOk" value="<?php echo $editNegocio;?>" />
      </p>
      
      <p>
      <label>
        <span>Tipo: <strong style="color: #363636;"><?php echo $editTipo;?></strong></span>
      </label>
          <input type="radio" name="editTipo" value="Casa" /> Casa  
          <input type="radio" name="editTipo" value="Apartamento" /> Apartamento  
          <input type="radio" name="editTipo" value="Duplex" /> Duplex  
          <input type="radio" name="editTipo" value="Condomínio" /> Condomínio  
          <input type="radio" name="editTipo" value="sala" /> Sala Comercial  
          <input type="radio" name="editTipo" value="pavilhão" /> Pavilhão  
          <input type="hidden" name="editTipoOk" value="<?php echo $editTipo;?>" />
       </p>  
         
      <label>
        <span>Valor:</span>
        <input type="text" name="editValor" value="<?php echo $editValor;?>" />
      </label>
      
      <label>
        <span>Descrição:</span>
        <textarea name="editDesc" cols="109" rows="5"><?php echo $editDesc;?></textarea>
      </label>



<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td>
    <label>
        <span>Comodos:</span>
        <input type="text" name="editComodos" value="<?php echo $editComodos;?>" />
      </label>
    </td>
    <td>
    <label>
        <span>Suites:</span>
        <input type="text" name="editSuites" value="<?php
		
         if($editSuites == ''){
			 $editSuites = 'Não Possui';
		 }else{
			 $editSuites = $editSuites;
		 } echo $editSuites;
		 
		  ?>" />
      </label>
    </td>
    <td>
    <label>
        <span>Banheiros:</span>
        <input type="text" name="editBanheiros" value="<?php echo $editBanheiros ;?>" />
      </label>
    </td>
    
    <td>
    <label>
        <span>Salas:</span>
        <input type="text" name="editSalas" value="<?php
		
         if($editSalas == ''){
			 $editSalas = 'Não Possui';
		 }else{
			 $editSalas = $editSalas;
		 } echo $editSalas;
		 
		  ?>" />
      </label>
    </td>
  </tr>
</table>

     
 <table width="100%" border="0" cellspacing="2" cellpadding="0">
   <tr>
    <td>
    <label>
        <span>Churrascaria:</span>
        <input type="text" name="editChurrasqueira" value="<?php
		
         if($editChurrasqueira == ''){
			 $editChurrasqueira = 'Não Possui';
		 }else{
			 $editChurrasqueira = $editChurrasqueira;
		 } echo $editChurrasqueira;
		 
		  ?>" />
      </label>
    </td>
    <td>
    <label>
    
        <span>Garagem:</span>
        <input type="text" name="editGaragem" value="<?php
		
         if($editGaragem == ''){
			 $editGaragem = 'Não Possui';
		 }else{
			 $editGaragem = $editGaragem;
		 } echo $editGaragem;
		 
		  ?>" />
      </label>
    </td>
    <td>
    <label>
        <span>Area de Serviço:</span>
        <input type="text" name="editServico" value="<?php
		
         if($editServico == ''){
			 $editServico = 'Não Possui';
		 }else{
			 $editServico = $editServico;
		 } echo $editServico;
		 
		  ?>" />
      </label>
    </td>
    <td>
    <label>
        <span>Piscina:</span>
        <input type="text" name="editPiscina" value="<?php
		
         if($editPiscina == ''){
			 $editPiscina = 'Não Possui';
		 }else{
			 $editPiscina = $editPiscina;
		 } echo $editPiscina;
		 
		  ?>" />
          
          
    </label>
    </td>
  </tr>
</table>

      <label>
        <span>Facilidades:</span>
        <input type="text" name="editFacilidades" value="<?php echo $editFacilidades;?>" size="110" />
      </label>
      
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td>
    <label>
        <span>Rua:</span>
        <input type="text" name="editRua" value="<?php echo $editRua;?>" size="97" />
      </label>
    </td>
    <td>
    <label>
        <span>Número:</span>
        <input type="text" name="editNumero" value="<?php echo $editNumero;?>" size="9" />
      </label>
    </td>
  </tr>
</table>  

<table>
  <tr>
    <td>
    <label>
        <span>Bairro:</span>
        <input type="text" name="editBairro" value="<?php echo $editBairro;?>" size="46" />
      </label>
    </td>
    <td>
    <label>
        <span>Próximo:</span>
        <input type="text" name="editProximo" value="<?php echo $editProximo;?>" size="60" />
      </label>   
    </td>
  </tr>

</table>
<input type="hidden" name="editId" value="<?php echo $editId;?>" />
<input type="submit" name="executar" id="executar" value="Aprovar Anúncio" />


    </form>
   <h1>Imagens do anúncio!</h1> 
   
   
<?php 
	//Comando para excluir imagens do anúncio
	if(isset($_POST['executar']) && $_POST['executar'] == 'Excluir'){
		$fotoId    = $_POST['fotoId'];
		$imovelImg = $_POST['imovelImg'];

		$sql_deletaImg = 'DELETE FROM  midias WHERE fotoId = :fotoId';
		try{
			$query_deletaImg = $conecta->prepare($sql_deletaImg);
			$query_deletaImg->bindValue(':fotoId',$fotoId,PDO::PARAM_STR);
			$query_deletaImg->execute();
			
			$pastaDel = '../midias';
			unlink($pastaDel.'/'.$imovelImg);
			echo '<div class="ok">Excluida</div>';
			
			}catch(PDOexception $error_delImg){
			  echo 'Erro ao excluir';
			}
	}

?>    
   
<!--Galeria para buscar as sub-imagens do anúncio-->   
<div class="galeria_all">
<?php
$sql_pegaImagem = 'SELECT * FROM midias WHERE imovelId = :imovelId';
try{
	$query_pegaImagem = $conecta->prepare($sql_pegaImagem);
	$query_pegaImagem->bindValue(':imovelId',$editId,PDO::PARAM_STR);
	$query_pegaImagem->execute();
	
	$resultado_pegaImagem = $query_pegaImagem->fetchAll(PDO::FETCH_ASSOC);
	
	}catch(PDOexception $error_pegaImagem){
	   echo 'Erro ao selecionar imagens';
	}
	
	foreach($resultado_pegaImagem as $resImagem){
		$fotoId = $resImagem['fotoId'];
		$imovelImg = $resImagem['imovelImg'];

?>

      <div class="galeria_cadastro">
      
      <span class="imagem"><img src="../midias/<?php echo $imovelImg;?>" width="100" alt="Exibição" /></span>
      <form name="execluirImagem" action="" enctype="multipart/form-data" method="post">
        <input type="hidden" name="imovelId" value="<?php echo $editId;?>" />
        <input type="hidden" name="fotoId" value="<?php echo $fotoId;?>" />
        <input type="hidden" name="imovelImg" value="<?php echo $imovelImg;?>" />
        <input type="submit" name="executar" id="executar" value="Excluir" />
      </form>
      
      
      </div><!--galeria cadastro-->
      
<?php
	}
?>
</div><!--fecha galeria all-->    
    

   </div><!--conteudo-->

</div><!--contet-->

Grato a todos.

 

 

Atenciosamente,

 

 

Renato

 

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.