Suppression entree mysql

crazyghandi Messages postés 323 Statut Membre -  
crazyghandi Messages postés 323 Statut Membre -
Bonjour,
Je voudrais supprimer une ou plusieurs entrees dans ma base de donnees.
Dans mon fichier list.php j'ai :

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("poker_db", $con);

$result = mysql_query("SELECT * FROM pkrtbl");

echo "<table border='1'>
<tr>
<th>Date</th>
<th>Type</th>
<th>Game</th>
<th>Cost</th>
<th>Buy-ins</th>
<th>Roll</th>
<th>Outcome</th>
<th>Winnings</th>
<th>Balance</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['game'] . "</td>";
echo "<td>" . $row['cost'] . "</td>";
echo "<td>" . $row['buyins'] . "</td>";
echo "<td>" . $row['roll'] . "</td>";
echo "<td>" . $row['outcome'] . "</td>";
echo "<td>" . $row['winnings'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

J'imagine que je dois rentre un input type checkbox et retourner toutes les valeurs positives vers un bouton supprimer mais je ne sais pas comment faire

quelqu'un aurait-t-il une idee svp ?

Merci d'avance
A voir également:

1 réponse

crazyghandi Messages postés 323 Statut Membre 19
 
Bon j'ai trouve la solution mais voici un autre probleme :

donc j'ai un check box a chaque ligne a laquelle je donne la valeur de la cle primaire de ladite ligne
ensuite je cree un bouton 'delete', jusque la tout va bien

seulmen je ne sais pas quelle variable comparer a la valeur "del" pour savoir si le checkbox est coche

voici le code :

<body>
<form name="delete" action="">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("poker_db", $con);

$result = mysql_query("SELECT * FROM pkrtbl");
$nb = 0;

echo "<table border='1'>
<tr>
<th>Date</th>
<th>Type</th>
<th>Game</th>
<th>Cost</th>
<th>Buy-ins</th>
<th>Roll</th>
<th>Outcome</th>
<th>Winnings</th>
<th>Balance</th>
<th></th>
</tr>";
if ($result){
while($row = mysql_fetch_array($result))
{
$nb++;
$n = $row['id'];
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['game'] . "</td>";
echo "<td>" . $row['cost'] . "</td>";
echo "<td>" . $row['buyins'] . "</td>";
echo "<td>" . $row['roll'] . "</td>";
echo "<td>" . $row['outcome'] . "</td>";
echo "<td>" . $row['winnings'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo "<td><input type='checkbox' name='$n' value='del'></td>";
echo "<td>","n : ",$n,"</td>";
echo "</tr>";
}
echo "</table>";
}else{
// echo "Table does not exist";
}
?>

<input type="submit" name="delete" value="DELETE">
</form>
<?php
echo $nb;
if (isset($_GET["delete"])) {
for ($i=1; $i<=$nb; $i++){
if ($_POST["$i"] == "del"){ QUE METTRE ICI POUR VOIR SI LA CHKBOX EST COCHEE??
echo $i,"is on";
}else{
echo $i,"is off";
}
}
echo "isset";
}
mysql_close($con);
?>
</body>

merci d'avance
0