Reply to Re: Newbie - Help required with deleting records in database

Your name:

Reply:


Posted by Martie on 05/19/06 19:57

On 17 May 2006 08:14:44 -0700, Dynamo wrote...
>
>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
>
>

Depending on the type of form you use (GET or POST method) you can probably use
a foreach() loop to check for all the $_GET or $_POST variables that are being
submitted. At the php.net site I found this sample that may help you out...

<?php
foreach ($_POST as $key => $value)
{
$checkboxname = $key;
$checkboxvalue = $value;
}
?>

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация