Supprimer un id d'une table

Bonjour,

j'aimerait suprimer un id d'une table en appuyant siu un bouton annuler comment dois-je m y prendre

merci

1 réponse

  1. Bonjour,
    Pour suppirimer une id dans une table mysql rien de plus simple :

    $rq = "DELETE * FROM "votre table" where id='Votre id a supprimer";
    $result = mysqli_query($connexion,$rq);

    En espérant avoir répondu à votre question.
    Flareski.
    0
    1. je vais te montrer une partie de mon code php

      //connextion a la base de donnee
      mysql_connect('localhost', 'auto7837', 'p_palm01');
      mysql_select_db("auto7837_auto");
      //prise de la derniere id
      $result = mysql_query("SELECT * FROM avendrenonpubliee ORDER BY id DESC LIMIT 0,1");
      $row = mysql_fetch_array($result);

      avec ca je ne peut pas vraiement donner un id car je selectionne le dernier
      0
    2. salut,
      tu veux faire quoi exactement ??
      tu veux supprimer un id au choix ??

      pour afficher tous les id de la table tu dois faire un while($row = mysql_fetch_array($result))

      exemple de code : (ce code permet d'afficher tous les id de la table dans un tableau avec un bouton supprimer a cote de chaque id pour le supprimer)

      // connection a la base de donnees

      echo "<table>
      <tr><th>ID</th><th>Supprimer</th><tr>";
      $result = mysql_query("SELECT * FROM nom_table") or die(mysql_error());
      while($row = mysql_fetch_array($result))
      {
      echo "
      <form action='supprimer.php' method='post'>
      <tr><td>$row[id]</td><td><input type='submit' value='supprimer'></td></tr>
      <input type='hidden' name='id' value='$row[id]'></form>";
      }
      echo "</table>";


      supprimer.php
      // connection a la base de donnees
      $id = $_POST['id']; // recuperation de l'id a supprimer
      $suppression = mysql_query("DELETE FROM test WHERE id = $id") or die(mysql_error());
      echo "<a href='Javascript:history.go(-1)'>Retour à la page précédente</a>"; // retour a la page precedente


      j'espere ke cé ca ce ke tu veux
      0
    3. ce n'est pas tout a fait ce que je veut voila ma page c est une page de previsualisation d'annonce et il y a un bouton annuler si le client ne veut plus publier l'annonce ce qui supprimera le id de sona annonce

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title>template</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

      <!-- Save for Web Styles (template.psd) -->
      <style type="text/css">
      <!--

      #Tableau_01 {
      position:absolute;
      left:50%;
      top:0px;
      width:910px;
      height:1369px;
      margin-left:-455px;
      }

      #template-01_ {
      position:absolute;
      left:0px;
      top:0px;
      width:910px;
      height:188px;
      }

      #template-02_ {
      position:absolute;
      left:0px;
      top:188px;
      width:153px;
      height:55px;
      }

      #template-03_ {
      position:absolute;
      left:153px;
      top:188px;
      width:140px;
      height:55px;
      }

      #template-04_ {
      position:absolute;
      left:293px;
      top:188px;
      width:152px;
      height:55px;
      }

      #template-05_ {
      position:absolute;
      left:445px;
      top:188px;
      width:155px;
      height:55px;
      }

      #template-06_ {
      position:absolute;
      left:600px;
      top:188px;
      width:3px;
      height:55px;
      }

      #template-07_ {
      position:absolute;
      left:603px;
      top:188px;
      width:149px;
      height:55px;
      }

      #template-08_ {
      position:absolute;
      left:752px;
      top:188px;
      width:158px;
      height:55px;
      }

      #template-09_ {
      position:absolute;
      left:0px;
      top:243px;
      width:910px;
      height:67px;
      }

      #template-10_ {
      position:absolute;
      left:0px;
      top:310px;
      width:910px;
      height:162px;
      }

      #template-11_ {
      position:absolute;
      left:0px;
      top:472px;
      width:258px;
      height:55px;
      }

      #template-12_ {
      position:absolute;
      left:258px;
      top:472px;
      width:390px;
      height:55px;
      }

      #template-13_ {
      position:absolute;
      left:648px;
      top:472px;
      width:262px;
      height:55px;
      }

      #template-14_ {
      position:absolute;
      left:0px;
      top:527px;
      width:910px;
      height:97px;
      }

      #template-15_ {
      position:absolute;
      left:0px;
      top:624px;
      width:299px;
      height:38px;
      }

      #template-16_ {
      position:absolute;
      left:299px;
      top:624px;
      width:10px;
      height:196px;
      }

      #template-17_ {
      position:absolute;
      left:309px;
      top:624px;
      width:2px;
      height:196px;
      }

      #template-18_ {
      position:absolute;
      left:311px;
      top:624px;
      width:284px;
      height:38px;
      }

      #template-19_ {
      position:absolute;
      left:595px;
      top:624px;
      width:10px;
      height:1px;
      }

      #template-20_ {
      position:absolute;
      left:605px;
      top:624px;
      width:305px;
      height:38px;
      }

      #template-21_ {
      position:absolute;
      left:595px;
      top:625px;
      width:10px;
      height:195px;
      }

      #template-22_ {
      position:absolute;
      left:0px;
      top:662px;
      width:299px;
      height:158px;
      }

      #template-23_ {
      position:absolute;
      left:311px;
      top:662px;
      width:284px;
      height:158px;
      }

      #template-24_ {
      position:absolute;
      left:434px;
      top:656px;
      width:305px;
      height:158px;
      }
      #couleur_bleue{color:#00F;
      }
      #prix {color:#00F; font-size:24px;
      }

      -->
      </style>
      <!-- End Save for Web Styles -->
      </head>
      <body style="background-color:#FFFFFF;">
      <!-- Save for Web Slices (template.psd) -->
      <div id="Tableau_01">
      <div id="template-01_">
      <img id="template_01" src="images/template_01.gif" width="910" height="188" alt="" />
      </div>
      <div id="template-02_">
      <img id="template_02" src="images/template_02.gif" width="153" height="55" alt="" />
      </div>
      <div id="template-03_"><img id="template_03" src="images/template_03.gif" width="140" height="55" alt="" /></div>
      <div id="template-04_">
      <img id="template_04" src="images/template_04.gif" width="152" height="55" alt="" />
      </div>
      <div id="template-05_">
      <img id="template_05" src="images/template_05.gif" width="155" height="55" alt="" />
      </div>
      <div id="template-06_">
      <img id="template_06" src="images/template_06.gif" width="3" height="55" alt="" />
      </div>
      <div id="template-07_">
      <img id="template_07" src="images/template_07.gif" width="149" height="55" alt="" />
      </div>
      <div id="template-08_">
      <img id="template_08" src="images/template_08.gif" width="158" height="55" alt="" />
      </div>
      <div id="Tableau_01">
      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p>
      <p>
      <?php
      //connextion a la base de donne
      //prise de la derniere id
      $result = mysql_query("SELECT * FROM avendrenonpubliee ORDER BY id DESC LIMIT 0,1");
      $row = mysql_fetch_array($result);

      ?>

      </p>
      <table width="910" border="0">
      <tr>
      <div id="couleur_blanche">
      <td height="30" background="images/barreannonce.png" style="background-repeat:no-repeat"><? echo '<span style="color:#FFFFFF;">'.$row["marque"].'</span>';?> <? echo '<span style="color:#FFFFFF;">'.$row["autres"].'</span>';?> <? echo '<span style="color:#FFFFFF;">'.$row["modele"].'</span>';?> <? echo '<span style="color:#FFFFFF;">'.$row["annee"].'</span>';?> <? echo '<span style="color:#FFFFFF;">'.$row["negociable"].'</span>';?>
      </td>
      </div>
      </tr>
      </table></td>
      <p> </p>
      <table width="844" border="0">
      <tr>
      <td width="409" height="76"><?php
      $i=1;
      if($row['image'.$i]) {
      echo '<center>
      <a href="photos/'.$row['image'.$i].'" alt="Voir image en grand" target=_BLANK>
      <img src="photos/'.$row['image'.$i].' " width="300">
      </a>
      </center>';
      } ?>

      </td>
      <td width="425" align="left" valign="top"><table width="411" border="0">
      <tr>
      <td width="211"><div id="couleur_bleue">Numéro de l'annonce:</div></td>
      <td width="190"><? echo '<span style="color:#00F;">'.$row["id"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Type d'annonce</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["typedannonce"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Catégorie de véhicule:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["etat"].'</span>';?></td>
      </tr>
      <tr>
      <td> </td>
      <td> </td>
      </tr>
      <tr>
      <td><div id="prix">Prix:</div></td>
      <td><div id="prix"><? echo '<span style="color:#00F; font-size:24px;">'.$row["prix"].'</span>';?>  FCFA</div></td>
      </tr>
      <tr>
      <td> </td>
      <td> </td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Kilométrage:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["kilometrage"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Nombre de cylindre:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["cylindre"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Puissance fiscale:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["puissance"].'</span>';?></td>
      </tr>
      </table>

      </td>
      </tr>
      </table>
      <table width="843" border="0">
      <tr>
      <td width="96" height="57" valign="top"><?php
      $i=2;
      if($row['image'.$i]) {
      echo '<center>
      <a href="photos/'.$row['image'.$i].'" alt="Voir image en grand" target=_BLANK>
      <img src="photos/'.$row['image'.$i].' " width="96">
      </a>
      </center>';
      } ?> </td>
      <td width="96" valign="top"><?php
      $i=3;
      if($row['image'.$i]) {
      echo '<center>
      <a href="photos/'.$row['image'.$i].'" alt="Voir image en grand" target=_BLANK>
      <img src="photos/'.$row['image'.$i].' " width="96">
      </a>
      </center>';
      } ?> </td>
      <td width="96" valign="top"><?php
      $i=4;
      if($row['image'.$i]) {
      echo '<center>
      <a href="photos/'.$row['image'.$i].'" alt="Voir image en grand" target=_BLANK>
      <img src="photos/'.$row['image'.$i].' " width="96">
      </a>
      </center>';
      } ?> </td>
      <td width="100" valign="top"><?php
      $i=5;
      if($row['image'.$i]) {
      echo '<center>
      <a href="photos/'.$row['image'.$i].'" alt="Voir image en grand" target=_BLANK>
      <img src="photos/'.$row['image'.$i].' " width="94">
      </a>
      </center>';
      } ?> </td>
      <td width="433"><table width="430" border="0">
      <tr>
      <td width="211"><div id="couleur_bleue">Consommation d'essence:</div></td>
      <td width="209"><? echo '<span style="color:#00F;">'.$row["consommation"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Carburant:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["carburant"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Transmission:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["transmission"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Immatriculé:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["immatricule"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Climatisation:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["climatisation"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Audio:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["audio"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Couleur intérieure:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["couleurinterieure"].'</span>';?></td>
      </tr>
      <tr>
      <td><div id="couleur_bleue">Couleur extérieure:</div></td>
      <td><? echo '<span style="color:#00F;">'.$row["couleurexterieure"].'</span>';?></td>
      </tr>
      </table></td>
      </tr>
      </table>
      <table width="843" height="244" border="0">
      <tr>
      <td width="416"> </td>
      <td width="199" valign="top"><div id="couleur_bleue">Message:</div></td>
      <td width="214" valign="top"><? echo '<span style="color:#00F;">'.$row["message"].'</span>';?></td>
      </tr>
      </table>
      <table width="843" border="0">
      <tr>
      <td width="411" align="right">
      <input type="submit" name="modifier" id="modifier" value="Modifier" />
      </td>
      <td width="64">
      <input type="submit" name="Annuler" id="Annuler" value="Annuler" />
      </td>
      <td width="354">
      <input type="submit" name="Envoyer" id="Envoyer" value="Envoyer" />
      </td>
      </tr>
      </table>
      <p> </p>
      </div>
      </div>
      <!-- End Save for Web Slices -->
      </body>
      </html>
      0