Category Sorting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elbejones
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 9:56 am

Category Sorting

Post by elbejones »

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.

Code: Select all

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();}
    }  



  }

}
elbejones
Forum Newbie
Posts: 4
Joined: Fri Apr 09, 2010 9:56 am

Re: Category Sorting

Post by elbejones »

Just to clarify

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

For example:
Category 3M Products b123, b124,..... b30,245

needs to change to
Category 3M||1 Products b123, b124,..... b1000
Category 3M||2 Products b1001, b1002,..... b2000
etc..
Post Reply