The same variable is repeated several times in the while

1

While words are appearing multiple times, eg:

macarrão
macarrão
macarrão
macarrão
macarrão
macarrão
arroz
arroz
arroz
arroz
arroz
arroz

What am I doing wrong?

<?php
$usuario=$_SESSION['email'];

require_once 'Classes/ProjetosVO.php';
require_once 'Classes/ProjetosDAO.php';

$mysqli = new mysqli('localhost', 'root', '', 'bdpi');

$objBDProjeto=new ProjetosDAO();
$objProjeto= new ProjetosVO();

$rsProjeto= $objBDProjeto->ListarProjetos("1");

$sqlProjetos="select P.codigo_PROJETO, P.nome_PROJETO from projetos P, usuarios U, funcoes F where U.email_USUARIO like '$usuario' and U.email_USUARIO=F.emailUsuario_FUNCAO and U.email_USUARIO=P.responsavel_PROJETO and F.status_FUNCAO=1 ";

$rsProjeto= mysqli_query($mysqli, $sqlProjetos) or die (mysqli_error($mysqli));

$tblProjeto=mysqli_fetch_array($rsProjeto);


?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><linkrel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/eb2dfeaa2c.js"></script><br><br><center><h1class="Titulo">Meus Projetos</h1></center>

&nbsp;&nbsp;
<?php
    include 'FormCadastraProjeto.php';
?>
<?php
    while($tblProjeto==mysqli_fetch_array($rsProjeto)){

?>
<a href="Projeto.php?codProjeto=<?=$tblProjeto['codigo_PROJETO'];?>" >      <h1><i class="fa fa-folder" aria-hidden="true"></i></h1>

<?php
    echo $tblProjeto['nome_PROJETO'];
?>
</a>

<?php
  }

?>
    
asked by anonymous 02.12.2017 / 05:03

3 answers

1

I do not know your table structure, but you can solve this by putting a distinct after select :

$sqlProjetos="select DISTINCT P.codigo_PROJETO, P.nome_PROJETO from projetos P, usuarios U, funcoes F..."

See if it will work like this.

    
02.12.2017 / 16:50
0

What are you comparing in this while ? Depending could use

foreach($tblProjeto as $tp){
?>
<a href="Projeto.php?codProjeto=<?=$tp['codigo_PROJETO'];?>" >      <h1><i class="fa fa-folder" aria-hidden="true"></i></h1>

    

    

02.12.2017 / 07:07
0

Your mysqli_fetch_array is repeated and misplaced in the while. See the comment for the line of your code below:

...$rsProjeto= mysqli_query($mysqli, $sqlProjetos) or die (mysqli_error($mysqli));

$tblProjeto=mysqli_fetch_array($rsProjeto);  // <<<--- Remova essa linha que está repetida com o while.

?>...

Then set up your while that is in the form of comparison with two equal signs (==) as follows:

<?php
    while($tblProjeto==mysqli_fetch_array($rsProjeto)){

?>

To:

<?php
    while($tblProjeto = mysqli_fetch_array($rsProjeto, MYSQLI_ASSOC)){

?>

You can still not know why the retry, but it may be because of these two lines, in addition to repeating the two lines, and doing a comparison mode in the while, if you do not put return mode of the php array will return all modes. What can cause repetition. It's a bit complicated to explain. But for you to do a test later with var_dump on your mysqli_fetch_array, and see what it returns.

But in the end, try to make those changes, and tell me if it helped. If you continue with the retry or some error, let me know.

    
03.12.2017 / 06:13