Forum Moderators: coopster

Message Too Old, No Replies

Table Synchronization

Deleting fields from one list where they exist in another...

         

inveni0

3:53 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



I'm trying to write a deletion script that will delete all fields from Table A that exist in Table B. I'm trying:

do {

$Exists = $row_BnBs['EMail'];
if ((isset($_GET['EMail'])) && ($_GET['EMail']!= "")) {
$deleteSQL = sprintf("DELETE FROM SalesList WHERE EMail=$Exists";
mysql_select_db($database_EditData, $EditData);
$Result1 = mysql_query($deleteSQL, $EditData) or die(mysql_error());

} while ($row_SalesList = mysql_fetch_assoc($SalesList));

This is not working. Is there another way to force this script to loop? Or, is there simply something wrong with the script I have?

inveni0

5:38 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



There was a missing ')' in that code. I fixed the typo, but it didn't help the script.

I've simplified the script to:

do {

$Exists = $row_BnBs['EMail'];

mysql_query("DELETE FROM SalesList WHERE EMail='$Exists'") or die(mysql_error());

} while ($row_SalesList = mysql_fetch_assoc($SalesList));

I'm still getting no response.

inveni0

8:40 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



I solved it. I had to change the 'while' statement.

I used:

//Begin Deletion Cycle

do {

$Exists = $row_BnBs['EMail'];

mysql_query("DELETE FROM SalesList WHERE EMail='$Exists'") or die(mysql_error());

} while ($row_BnBs = mysql_fetch_assoc($BnBs));

coopster

9:26 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Which version of MySQL are you running there?

inveni0

9:34 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



4.0.13

Why?

coopster

9:52 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As of MySQL 4.1 you could have run a subquery instead of one query, then another. But your workaround is your best bet for now.