graphanco Posted February 5, 2016 Share Posted February 5, 2016 I have some troubles with my sql while () : It works once then stop and doesn't print the other results. The select count works well. Have you got an idea ? <?phpif(isset($_POST['produit'])){$produit = $_POST['produit'];}$requete='SELECT * FROM `references_tplg` WHERE ';$requete_count='SELECT COUNT(id) as total FROM `references_tplg` WHERE ';if($produit != '0') {$requete=$requete.'`produit`="'.$produit.'"';$requete_count = $requete_count.'`produit`="'.$produit.'"';}$requete = $requete.' ORDER BY id ASC';$requete_count = $requete_count.' ORDER BY id ASC';$sqlcount=mysqli_query($bdd, $requete_count);while ($row1 = mysqli_fetch_array($sqlcount)){ $total=$row1['total'];}if ($total=='0') { echo 'Il n\'y a pas de résultats pour votre recherche. <br> Nous vous conseillons de réitérer votre recherche en limitant le nombre d\'option sélectionné'; }else if ($total>0){ echo 'Vous avez '.$total.' résultat(s) à votre recherche.<br><br>'; }$sql=mysqli_query($bdd, $requete)while ($row = mysqli_fetch_array($sql)){$produit=stripslashes($row['produit']);if ($produit == '1'){ $produit_ok='texte1';}else if ($produit == '2'){ $produit_ok='texte2';}?><hr /><?php if($produit_ok != '') { ?><h2>Produit : <?php echo $produit_ok; ?></h2><?php } ?><?php } ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2016 Share Posted February 5, 2016 If $_POST['produit'] is 0 then that query is going to have a syntax error. Otherwise the code looks fine. Link to comment Share on other sites More sharing options...
graphanco Posted February 8, 2016 Author Share Posted February 8, 2016 ok thank you, but I confirme I cheak all and it give me only the first field of my database. If you have an idea it will be nice. It'd help me very much. Thank u. Link to comment Share on other sites More sharing options...
graphanco Posted February 8, 2016 Author Share Posted February 8, 2016 that works ! thank u Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now