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! Link to comment https://forums.phpfreaks.com/topic/121265-php-loop-into-sql-query/ 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"? Link to comment https://forums.phpfreaks.com/topic/121265-php-loop-into-sql-query/#findComment-625291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.