PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?PHP
$val = $_POST['val'];
mysql_query("DELETE FROM pm WHERE val=$val");
?>
which would work fine for deleteing one row but I would like it to delete a few more than that and wouldnt really want to make a huge page with a lot of 'if' statements or anything, im thinking a loop might work or something like that. What would you guys suggest on this one?
foreach ($_POST['val'] as $value)
{
$sql = '
DELETE FROM table_name WHERE value = "'.$value.'"
';
$do_query = mysql_query($sql) or die(mysql_error());
}
$sql = 'DELETE FROM table name WHERE ';
foreach ($_POST['val'] as $value)
{
$sql .= 'row_name ='.$value.', ';
}
//then take the last 5 characters off of $sql which is the space, comma then the word AND
//then do the query, this would make only one mysql query and make for a faster script