Résultat d'un select qui ne s'affiche pas dans un tableau (<table></table>)

Répondre
oroch
le 08/12/2010 à 20:50
oroch
Bonjour à tous. Voilà je récupère les résultats d'une requête mysql et je souhaite les mettre dans un tableau. Or dans le tableau des lignes apparaissent mais rien ne s'affiche. Merci d'avance pour votre aide :)
Voici mon code:
  1. <!DOCTYPE html PUBLIC "-
  2. //W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
  3. strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7. <link rel="stylesheet" type="text/css" href="consultprix.css">
  8. </head>
  9. <body>
  10. <div>
  11. <h3>Choisir une tranche de prix :</h3>
  12. <form method="post">
  13. <p id="inf"><input type="radio" name="prix" <?php if (isset($_POST["prix"])) { if ($_POST["prix"] == "1"){ echo 'checked="checked"'; }} ?> value="1" > < 200.000 € </p>
  14. <input type="radio" name="prix" <?php if (isset($_POST["prix"])) { if ($_POST["prix"] == "2"){ echo 'checked="checked"'; }} ?> value="2" > de 200.000 € à 300.000 € <br/>
  15. <p id="sup"><input type="radio" name="prix" <?php if (isset($_POST["prix"])) { if ($_POST["prix"] == "3"){ echo 'checked="checked"'; }} ?> value="3" > > 300.000 € </p>
  16. <input type="submit" name="afficher" value="Afficher"> <br/>
  17. </form>
  18. </div>
  19. <br/><br/><hr/><br/>
  20. <?php
  21. if (isset($_POST["afficher"]))
  22. {
  23. $conn = mysql_connect ("localhost","root","") or die ("Connexion impossible");
  24. $base="umy63";
  25. mysql_select_db("$base") or die ("Base inconnue");
  26. print("Connexion réussie à la base : $base");
  27. if (isset($_POST["prix"]))
  28. {
  29. if ($_POST["prix"] == "1")
  30. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien < 200000;';
  31. else
  32. {
  33. if ($_POST["prix"] == "2")
  34. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien > 200000 and b.prixbien < 300000;';
  35. else
  36. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien > 300000;';
  37. }
  38. }
  39. ?>
  40. <center><table width="100%" border="1">
  41. <tr><td>Identificateur </td>
  42. <td>Détail </td>
  43. <td>Prix </td>
  44. <td>NomType </td>
  45. <td>Photo</td><?php
  46. $result = mysql_query($requete,$conn);
  47. if(mysql_errno()==0)
  48. {
  49. if($result)
  50. {
  51. while($row = mysql_fetch_array($result))
  52. {
  53. ?>
  54. <tr><td>
  55. <? echo $row["idbien"]; ?>
  56. </td><td>
  57. <? echo $row["detailbien"]; ?>
  58. </td><td>
  59. <? echo $row["prixbien"]; ?>
  60. </td><td>
  61. <? echo $row["nomtype"]; ?>
  62. </td><td>
  63. <? echo $row["photobien"]; ?>
  64. </td><tr>
  65. <?php
  66. }
  67. ?></table><?php
  68. mysql_free_result($result);
  69. }
  70. else
  71. {
  72. echo "Pas de biens trouvé<br/>";
  73. }
  74. }
  75. else
  76. {
  77. echo "Problème sur le select ...<br/>";
  78. echo mysql_errno().": ".mysql_error()."<br/>";
  79. }
  80. mysql_close($conn);
  81. }?>
  82. </body>
  83. </html>
i M@N
le 09/12/2010 à 18:50
i M@N
Hello.

Avec un peu de concatéation ce serait plus simple. initialise ton POST et sers-toi de $rix.
Essaye avec un truc comme ça :
  1. <?php
  2. if (isset($_POST["prix"])) $prix = $_POST["prix"];

  3. ?>
  4. <!DOCTYPE html PUBLIC "-
  5. //W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
  6. strict.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  10. <link rel="stylesheet" type="text/css" href="consultprix.css">
  11. </head>
  12. <body>
  13. <div>
  14. <h3>Choisir une tranche de prix :</h3>
  15. <form method="post">
  16. <p id="inf"><input type="radio" name="prix"

  17. <?php

  18. if ($prix == "1") {

  19. echo 'checked="checked"';

  20. }

  21. ?>

  22. value="1" > &lt; 200.000 € </p>
  23. <input type="radio" name="prix"

  24. <?php

  25. if ($prix == "2") {

  26. echo 'checked="checked"';

  27. }

  28. ?>

  29. value="2" > de 200.000 € à 300.000 € <br />
  30. <p id="sup"><input type="radio" name="prix"

  31. <?php

  32. if ($prix == "3") {

  33. echo 'checked="checked"';

  34. }

  35. ?>

  36. value="3" > &gt; 300.000 € </p>
  37. <input type="submit" name="afficher" value="Afficher"> <br />
  38. </form>
  39. </div>
  40. <br />
  41. <br />
  42. <hr/>
  43. <br />
  44. <?php
  45. if (isset($_POST["afficher"])) {
  46. $conn = mysql_connect ("localhost","root","") or die ("Connexion impossible");
  47. $base="umy63";
  48. mysql_select_db("$base") or die ("Base inconnue");
  49. print("Connexion réussie à la base :$base");
  50. if (isset($prix)) {
  51. if ($prix == "1") {
  52. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien < 200000;';
  53. }
  54. elseif ($prix == "2") {
  55. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien > 200000 and b.prixbien < 300000;';
  56. }
  57. else {
  58. $requete='select b.idbien,b.detailbien,b.prixbien,t.nomtype, b.photobien from bien b, typebien t where b.idtype = t.idtype and b.prixbien > 300000;';
  59. }
  60. }
  61. echo '<center>
  62. <table width="100%" border="1">
  63. <tr>
  64. <td>Identificateur </td>
  65. <td>Détail </td>
  66. <td>Prix </td>
  67. <td>NomType </td>
  68. <td>Photo</td>
  69. </tr>';


  70. $result = mysql_query($requete,$conn);
  71. if(mysql_errno()==0) {
  72. if($result) {
  73. while($row = mysql_fetch_array($result)) {
  74. echo '<tr>
  75. <td>'.$row["idbien"].'</td>
  76. <td>'.$row["detailbien"].'</td>
  77. <td>'.$row["prixbien"].'</td>
  78. <td>'.$row["nomtype"].'</td>
  79. <td>'.$row["photobien"].'</td>
  80. </tr>';

  81. }
  82. echo '</table>';


  83. mysql_free_result($result);
  84. }
  85. else {
  86. echo "Pas de biens trouvé<br />";
  87. }


  88. }
  89. else {
  90. echo "Problème sur le select ...<br />";
  91. echo mysql_errno().": ".mysql_error()."<br />";
  92. }
  93. mysql_close($conn);
  94. }

  95. ?>


  96. </body>
  97. </html>


@+...
One Love, One Heart, One Unity.
Répondre

Ecrire un message

Votre message vient d'être créé avec succès.
LoadingChargement en cours