Hi all, does anyone know of a good way to delete groups of records in mysql? Lets say the database has 3 fields:
id (unique index autonumber)
city (text)
address (text)
I want to delete all records from this database EXCEPT those records with these values in the city field:
Racine
Kenosha
Franklin
Caledonia
Franksville
Delavan
Bristol
Milwaukee
I came up with something like this and it is getting hung up, i bet i am probably using DELETE incorectly? Anyway here is what i have so far. Again doesnt have to be php, just want a way that i can remove all records EXCEPT specified cities:
<?
include 'servars.php';
$connect = mysql_connect("$dbhost", "$dbuser", "$dbpass");
mysql_select_db($dbname);
$query = "SELECT * from wiphone";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result))
{
if ($row[city] == "Racine" || $row[city] == "Kenosha" || $row[city] == "Franklin" || $row[city] == "Caledonia" || $row[city] == "Sturtevant" || $row[city] == "Sturtevant" || $row[city] == "Franksville" || $row[city] == "Delavan" || $row[city] == "Bristol" || $row[city] == "Milwaukee")
{
$savecity = $row[city];
}
else
{
$query = "DELETE FROM wiphone WHERE id = $row[id]";
$result = mysql_query($query);
}
}
?>
Thanks for looking!