note 78423 added to control-structures.foreach
| From: | arasam1 at yahoo dot com | Date: | Thu, 11 Oct 2007 12:12:28 +0000 |
| Subject: | note 78423 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131302@lists.php.net to get a copy of this message | ||
Hi guys, I created a form, that shows people who signed up for an event. So I want to put a checkbox
near every people name, so when I click the checkboxs the names are deleted from the DB. Here is the
code that shows the output:
[code]
$Result = mysql_query("SELECT * FROM vlist ORDER BY 'id'",$link);
echo "<form name='check' action='checked.php'
method='post'>";
echo "<table name='app' cellpadding='0'>";
echo "<tr bgcolor='#eeeeee'>";
echo "<th name='id'></th><th name='eso'>ESO
Username</th><th name='email'>e-mail</th><th
name='country'>country</th><th
name='contacted'>Contacted</th>";
echo "</tr>";
while ($Row = mysql_fetch_row($Result))
{
if ($Row[4]== "true") { $Row[4] = "<img src='check.gif'>";}
if ($Row[4]== "false") { $Row[4] = "<img src='x.gif'>";}
printf ("<tr><td align='center'>%s</td><td
align='center'>%s</td><td align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td><input name='to_delete[]'
value='$Row[0]' type='checkbox'/></td></tr>",
$Row[0], $Row[1], $Row[2], $Row[3], $Row[4] );
}
echo "</table>";
echo "<input type='submit' name='submit'
value='Submit'>";
echo "</form>";
[/code]
And here is the delete page:
[code]
// Retrieve all keys that point to "true"
$contacted = array_keys($_POST, true);
if ($contacted == true) {
$condition = "id = " . $value;
while ($value = next($contacted)) {
$condition .= " OR id = $value";
}
// Create & execute query
$query = "DELETE FROM vlist WHERE " . $condition;
$result = mysql_query($query);
[/code]
But as you might have guessed it doesnt work. THanks for your help!
----
Server IP: 69.147.83.197
Probable Submitter: 65.92.214.210
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/78423
Del: integrated -- https://master.php.net/note/delete/78423/integrated
Del: useless -- https://master.php.net/note/delete/78423/useless
Del: bad code -- https://master.php.net/note/delete/78423/bad+code
Del: spam -- https://master.php.net/note/delete/78423/spam
Del: non-english -- https://master.php.net/note/delete/78423/non-english
Del: in docs -- https://master.php.net/note/delete/78423/in+docs
Del: other reasons-- https://master.php.net/note/delete/78423
Reject -- https://master.php.net/note/reject/78423
Search -- https://master.php.net/manage/user-notes.php