Query does not return results in PHP

Asked

Viewed 199 times

0

There is a query in my PHP where you search the email list and return to PHP, however, it is not returning any results.

The PHP Code looks like this:

      <?php
      session_start("admin");
      if($_SESSION["admin"] == "on"){
      include("../config.php");
      ?>
      <?php
      $sql = mysql_query("SELECT `email` FROM `n_emails` WHERE 1");
      $resultado = mysql_query($sql) or die(mysql_error());
      while($lista2=mysql_fetch_array($resultado)) {
      $email = $lista2["email"];
      $ativo = $lista2["ativo"];
      if($ativo=="n"){
      $ativo = "<font face='Arial' size='2' color='red'>Não confirmado</font>";
      }
      else{
      $ativo = "<font face='Arial' size='2' color='green'>Confirmado</font>";
      }
      ?>
      <tr>
      <td width="50%">
      <p align="center"><b><font face="Arial" size="2"><?=$email?></font>          </b></td>
      <td width="25%"><?=$ativo?></td>
      <td width="25%"><a href="javascript:remove('<?=$email?>')">
      <font face="Arial" size="2">remover</font></a></td>
      </tr><?php } ?>
      <?php
      }
      else{
      echo "<script>location.href='login.php'</script>";
      }
      ?>

When I run this query manually, it returns all the correct results. I don’t understand what is happening.

  • Enter the most complete code. The problem is not in the query.

  • @Filipemoraes Basically that’s it

  • 1

    You are selecting wrong. Delete this WHERE 1.

  • solved, just change the query, thanks Denis and Filipe

1 answer

1


Solution to the problem, I changed the query:

  SELECT `email` FROM `n_emails` WHERE 1

for that:

  SELECT * FROM n_emails order by -id

And it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.