I need to delete some data from mysql. I know a bit of php but get really lost with mysql and really don't want to mess this up... I did make a .sql backup but I need to get this right. That's why i'm posting the question here. I know I will get some crap for not trying myself and posting my code here but to be hosnest.. this is as far as I got before I got stuck:
$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DATABASE", $con);
$result = mysql_query("SELECT * FROM subscriber");
while($row = mysql_fetch_array($result))
{
echo $row['mail'] . " " . $row['snid'];
echo "
";
}
mysql_close($con);
?>
What i'm really trying to do is this:
Locate all rows where status = 0 the in the table called subscription and get the field snid (which is an integer)
Then go to the table called subscriber and delete the row with the matching snid (also a field in this tables row)
Then go back to subscription and delete the original matched row
Does this make sence?.... I've done my own head in just trying to explain it :(
解决方案
To do what you've asked, you only need 1 query:
delete subscriber, subscription from subscriber,subscription where subscription.status = 0 and subscription.snid=subscriber.snid;