note 78423 rejected from control-structures.foreach by nlopess
| From: | nlopess@php.net | Date: | Sun, 21 Oct 2007 21:55:47 +0000 |
| Subject: | note 78423 rejected from control-structures.foreach by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131600@lists.php.net to get a copy of this message | ||
Note Submitter: arasam1 at yahoo dot com
----
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!