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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.