Posted by Dynamo on 05/17/06 18:14
Hi,
I'm still relatively new to php and sql and need some help with deleting records
from a database. My objective is to create a user friendly web page where I can
list all the records held within a database and have a check box by the side of
each record. Then I want all of those records where the check box is ticked to
be selected and deleted from the database. The coding I have below selects all
the records and inserts a check box by the side of each record. The check box
assumes the same name as the ID number of each record. Thats as far as I've got.
If someone could point me in the right direction for the rest of the coding
required to achieve my objective I would be extremely grateful.
<?php
$query = "SELECT * FROM Catalogue";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=2 border=0>";
$r == 0;
echo "<tr>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Cat No</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Click on the thumbnail to view a detailed
decscription</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Description</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Price</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Stock Availability</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Postage and packaging</b></u></font></td>";
echo "<td bgcolor='#DF7000' valign='top' align='center'><font face='Arial'
size='1' color='#FFFFCC'><u><b>Delete this item</b></u></font></td>";
echo "</tr>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><p align='center'><font face='Arial' size='1'>" . $row[0] .
"</font></td>";
echo "<td><p align='center'><a href='desc.php?image=$row[0]'><img border='0'
src='/thumbnails/$row[2]'></a></td>";
echo "<td><p align='center'><font face='Arial' size='1'>" . $row[3] .
"</font></td>";
echo "<td><p align='center'><font face='Arial' size='1'>£" . $row[6] .
"</font></td>";
echo "<td><p align='center'><font face='Arial' size='1'>" . $row[7] .
"</font></td>";
echo "<td><p align='center'><font face='Arial' size='1'>£" . $row[8] .
"</font></td>";
?>
<td><p align='center'><input type='checkbox' name='<?php echo $row[0];?>'
value='ON'></td>
<?php
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
Thanks in advance
Dynamo
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
[Back to original message]
|