Jump to content

php loop into sql query


ahs10

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.