Jump to content
Fórum Script Brasil
  • 0

Erro em Where


claytonprog

Question

Pessoal!

Olha eu de novo aqui.

É o seguinte estou com uma sql com erro dêem uma olhada:

$strSQL = mysql_query("SELECT * FROM cursos where $hoje >= dt_insc_fin or dt_insc_fin <> "0000-00-00" order by data desc LIMIT $start,$plimit"); // está dando erro

Preciso que só apareçam os cursos que estejam com datas maior ou igual a data do dia e os cursos que não estiverme com a data final vazia.

Alguém pode me dar uma ajuda?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Há problemas com o escapamento de caracteres e de lógica.

Por exemplo, ao invés de OR, você deve usar AND, e o operador de desigualdade é o !=, e não o <>.

Quando você usa aspas duplas no meio de uma string, você a interrompe, e o que tiver depois dela só fará parte da string se concatenado com o sinal de ponto.

Acho que isso deve funcionar:

$strSQL = mysql_query("SELECT * FROM `cursos` WHERE `dt_insc_fin` >= '".$hoje."' OR `dt_insc_fin` != '0000-00-00' ORDER BY `data` DESC LIMIT ".$start.", ".$plimit."");

Lembrando que você deve obedecer o formato de data presente no banco de dados.

Link to comment
Share on other sites

  • 0

Ainda não funcionou direito. existem 2 cursos com data final de: 30-01-2012 e 09-01-2012 que estão aparecendo.

código está assim:

<!-- Início Cursos Box -->
                 
                  <?php

                        // conexão com o banco de dados
                         include "connections/conexao.php";
                        
                        
                        $newp = @$_GET["p"];
                        if (!is_numeric ($newp)) {
                        $newp= 1;
                        }
                        
                        $plimit = "8";// limite de linha para exibição
                        
                        $hoje = date("Y-m-d");        
                        
                                            
                        $strSQL = mysql_query("SELECT * FROM cursos WHERE dt_insc_fin >= '".$hoje."' OR dt_insc_fin != '0000-00-00'");
                        
                        $totalrows = mysql_num_rows($strSQL);
                        $pnums = ceil ($totalrows/$plimit);
                        
                        if ($newp==''){ $newp='1'; }
                        
                        $start = ($newp-1) * $plimit;
                        $starting_no = $start + 1;
                        
                        if ($totalrows - $start < $plimit) { $end_count = $totalrows;
                        } elseif ($totalrows - $start >= $plimit) { $end_count = $start + $plimit; }
                        
                        ?>
            
            
                        <?php
                        
                        $hoje = date("Y-m-d");                     
                    
                        
                        $strSQL = mysql_query("SELECT * FROM cursos WHERE dt_insc_fin >= '".$hoje."' OR dt_insc_fin != '0000-00-00' ORDER BY data DESC LIMIT ".$start.", ".$plimit."");
                        
                        while ($aux = mysql_fetch_array($strSQL)) {
                                    
                        $id = $aux['id'];
                        $foto = $aux['foto'];
                        $titulo = $aux["nome"];    
                        $dt_insc_fin= $linha['dt_insc_fin'];
                        $vagas = $aux['vagas'];                                            
                                                                        
                        ?>
                
                     <div class="portfolio-2col-box "> 
                    
                                                                             
                    <a href='ver_curso.php?id=<? echo $aux['id']; ?>'><img src="painel/<? echo $aux['foto']; ?>" /></a>                           
                    
                    <p>&nbsp;</p>
                            
                    <h2><a href="ver_curso.php?id=<? echo $aux['id']; ?>" class="readmore"><? echo $aux['nome']; ?></a></h2>                          
                     
                    <p>&nbsp;</p> 
                        
                    </div>
                    
                     
                    
                    
                  <?php
                    }
                   ?> 
                   
                    
                    <!-- Final Cursos Box -->

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...