ahs10 Posted August 25, 2008 Share Posted August 25, 2008 i'd like to turn this php loop into an sql query. can someone help me do that please? <?php $all = mysql_query("SELECT product_number, order_number, tracking_number FROM dhl92") or die(mysql_error()); while ($row = mysql_fetch_array($all)) { $matches = myql_query("SELECT id FROM dhl92 WHERE product_number = '" . $row['product_number'] . "' AND order_number = '" . $row['order_number'] . "' AND tracking_number = '" . $row['tracking_number'] . "'") or die(mysql_error()); $count = mysql_num_rows($matches); for ($i = 1; $i < $count; $i++) { $result = mysql_result($matches, $i); $remove = mysql_query("DELETE FROM dhl92 WHERE id = '" . $result . "'") or die(mysql_error()); } } ?> this will remove all but one row that have the same product_number, order_number, and tracking_number. any help is much appreciated. thanks! Quote Link to comment Share on other sites More sharing options...
fenway Posted August 25, 2008 Share Posted August 25, 2008 Why the outer query? And why not use the second query ($matches) but just replace "SELECT id" with "DELETE"? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.