I've been writing some lines recently trying to work this issue out. I have a table where I want to store a list of names of films.
I got it to work (inserting the data, outputting also works) but I can't manage to get to delete a row.
Each row consists of another film, with:
- ID (primary key)
- Title
- Director
- Year
Each time a row gets deleted, it seems like the enitre row is gone.
For example if I insert 4 titles, and delete those 4 afterwards, the next film added will be marked as #5, instead of #1. Does that make sense?
Thanks in advance!
Here's the code:
<?php
$usr = " ";
$pwd = " ";
$db = " ";
$host = " ";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
if ($task=="del") {
$SQL = " DELETE FROM overview ";
$SQL = $SQL . " WHERE id = $id ";
mysql_db_query($db, $SQL, $cid);
}
?>
<?php
echo "<table border='0'>
<tr>
<th>#</th>
<th>Name</th>
<th>Director</th>
<th>Year</th>
<th>Delete</th>
</tr>";
$SQL = " SELECT * FROM overview ";
$retid = mysql_db_query($db, $SQL, $cid);
if (!$retid) { echo( mysql_error()); }
else {
echo ("<p><table cellpadding=4>\n");
while ($row = mysql_fetch_array($retid)) {
$id = $row["id"];
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['director'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo ("<td><a href=\"list_del.php?id=$id&task=del\">x</a></td>");
echo "</tr>";
}
echo ("</table>");
}
mysql_close($cid);
?>


Sign In
Create Account


Back to top









