php - While loops duplicating the results -


i have 2 rows in table , when while loop fetch in php duplicates results 5 times. can see creates table , there 2 rows seems strange duplicate results.. found answered here on stackoverflow saying add "distinct" on query , doesnt work on mine...

    <?php // sessão precisa ser iniciada em cada página diferente $id=null; session_start(); if (isset($_session['usuarioid'])) {     $id = $_session['usuarioid']; } ?>     <head>     <link href="css/style.css" rel="stylesheet" type="text/css" />     <link rel="shortcut icon" href="http://www.iconj.com/ico/7/5/75jqn04zq9.ico" type="image/x-icon" />     <title>verificar estado</title></head>     <body>     </div><?php     //tentativa de estabelecer uma ligação à bd     $connection = new mysqli('***', '***', '****', '****');      //verificar se ligação foi estabelecida com sucesso     if (mysqli_connect_errno() ) {         echo "</h2>erro no acesso à base de dados.</h2>" . mysqli_connect_error();          exit();         }        $sql = "select distinct id_user, id_ficha, avaria, observacoes, estado, id fichas, usuarios id_user = " . $id.";";     //executar query!      $result = $connection->query($sql);     echo "<div id='listanomes'>user id - id ficha - avaria</div>";     ?>     <div id="lista">     <div class="estados">     <?php     while ($userproduto = $result->fetch_object()) {         echo '<table border="1">';         echo "<tr>";             echo "<td>" . $userproduto->id_user . "</td>";             echo "<td>" . $userproduto->id_ficha . "</td>";             echo "<td>" . $userproduto->avaria . "</td>";             echo "<td>" . $userproduto->observacoes . "</td>";             echo "<td>" . $userproduto->estado . "</td>";             echo "</tr>";         echo "</table>";     }           echo '</div>';         echo '</div>';     //termina o script          echo '<div class="foot">';         echo '<p>copyright © 2013 - todos os direitos reservados - <a href="mailto:numica@numica.pt">númica</a></p>';         echo '</div>';         echo '</body>';         echo '</html>';     exit();     ?> 

you have add join statement join 2 tables, otherwise sql cartesian product.

select distinct id_user, id_ficha, avaria, observacoes, estado, id fichas, usuarios id_user = $id , fichas.id = usarios.id_fichas 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -