sorting categories

I am working on a large website with over 1 mil products that are separated into manufacturers, however some of the categories (or manufacturers) have 30 k products. The customer requested that I split these into 1,000 per category. I am working from a batch of excels that I imported into my home server and this is what I have for now, I am adding an incremented number as a sub category. its obviously not working since im here. Thanks in advance for your help.

[php]
function distinct_manus() {
global $c;
$q = " SELECT DISTINCT Manufacturer as Manufacturer ";
$q .= " FROM products ";
$r = mysql_query($q, $c);
confirm_query($r);
return $r;
}

function distinct_manu_prods($Manufacturer) {
global $c;
$q = " SELECT * ";
$q .= " FROM products “;
$q .= " WHERE Manufacturer =’$Manufacturer’”;
$r = mysql_query($q, $c);
confirm_query($r);
return $r;
}

$num_passes=0;
$distinct_manus = distinct_manus();
while ($distinct_manu = mysql_fetch_array($distinct_manus)){
$Manufacturer = $distinct_manu[Manufacturer];
$products = distinct_manu_prods($Manufacturer);
$num_products = mysql_num_rows($products);
if (mysql_num_rows($products) > 1000) {
while ($product = mysql_fetch_array($products)){
$run = $product[Category]."||1";
$q = “UPDATE products SET Category = {$run}”;
if (mysql_query($q,$c)){echo “Edit Successful.”;
} else {echo "Error message = ".mysql_error();}
}

}

}
[/php]

Just to clarify

First I need to find the distinct manufacturers(categories)
Get the manufacturers(categories) with more than 1000 products
Add sub categories (with category separator “||” until they all have 1000 or less products

For example:
Category 3M SKUs b123 b124… b30,245

needs to change to
Category 3M||1 SKUs b123 b124… b1000
Category 3M||2 SKUs b1001 b1002… b2000
etc…

Sponsor our Newsletter | Privacy Policy | Terms of Service