miiidooo-19 Posted April 30, 2012 Share Posted April 30, 2012 bonjour, j'ai crée un fichier hors de la boutique je l'ai liée a la bdd de la boutique et quand je fait une simple requete sql ça s'affiche pas les résultats :s exemple <?php $req=mysql_query('SELECT * FROM ps_product ')or die(mysql_error()); $nb=mysql_num_rows($req); echo 'total lignes : '.$nb.'<br/>'; while ($result=mysql_fetch_assoc($req)) { echo 'id de produit : '.$result->id_product; echo '<br />'; } ?> le résultat qu'il doit s'afficher normalement c'est : total lignes : 7 id de produit : 1 id de produit : 2 id de produit : 3 id de produit : 4 id de produit : 5 id de produit : 6 id de produit : 7 et les résultats qui s'affiche maintenant c'est total lignes : 7 id de produit : id de produit : id de produit : id de produit : id de produit : id de produit : id de produit : d'ou vien l'erreur Link to comment Share on other sites More sharing options...
miiidooo-19 Posted April 30, 2012 Author Share Posted April 30, 2012 :'( c'est vraiment urgent S'il vous plait Link to comment Share on other sites More sharing options...
manouille Posted April 30, 2012 Share Posted April 30, 2012 Salut, pas facile le php Si tu veux utiliser mysql_fetch_assoc il faut écrire : <?php $req=mysql_query('SELECT * FROM ps_product ')or die(mysql_error()); $nb=mysql_num_rows($req); echo 'total lignes : '.$nb.'<br/>'; while ($result=mysql_fetch_assoc($req)) { echo 'id de produit'; echo $result["id_product"]; echo '<br />'; } ?> Mais mon petit doigt me dit que tu aurais plutot besoin de mysql_fetch_object qu'il faudra écrire comme cela : <?php $req=mysql_query('SELECT * FROM ps_product ')or die(mysql_error()); $nb=mysql_num_rows($req); echo 'total lignes : '.$nb.'<br/>'; while ($result=mysql_fetch_object($req)) { echo 'id de produit : '; echo $result->id_product; echo '<br />'; } ?> Bon courage. Link to comment Share on other sites More sharing options...
IchabOd Posted April 30, 2012 Share Posted April 30, 2012 oui si tu ne crées pas un objet de tes lignes, tu ne peux pas le gérer comme tel. 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