Supertex Posted January 7, 2014 Posted January 7, 2014 I would like to be able to take a category of products, and auto-enumerate the products_model field, based on ascending products_sort_order. I need to specify the range and increment. I need the capacity to leave gaps in the sequence. Hence the range, rather than just a starting figure. Selection could be via products_to_categories, or partial match of existing products_model...that much I can handle.But how to achieve the enumeration has me stumped - both the iterations and how to keep it "lined up" with sort order. I've learned a great deal by examining small scripts and modifying them, I just haven't learned enough - yet.. Example: Look for all models beginning with "123" and append from "500" to "995" by "5" or Look for all products in category "X", and set model=(123500 to 123995 by 5) to end up with model numbers of: 123500, 123505, ......123895, 123990, 123995. Anyone feel like guiding me a bit? osC v2.3.1 MySQL v8.0.32 PHP v5.6.40 Installed addons: . Attribute Sets Plus .. Create Account & Manual Order Maker .. Customer Testimonials 2.3.4 .. Customer Blacklist .. Dynamic Info Pages .. FedEx Web Svcs v9 .. Filtered Sales Report .. Generic Box .. Google XML Sitemap SEO .. Maximum Order Value .. Modular Front Page .. Monthly Sales & Tax Report .. Multiple Products Manager .. Must Accept Terms & Conditions .. Order Editior .. PDF Customer Invoice .. Price in Cart Only .. Product Sort/Order .. Product Sort in Cart .. Quantity Discounts .. Restrict Delivery Methods .. SEO Header Tags - Reloaded .. Separate Pricing Per Customer .. Simpler Admin Session Length Control .. Sitemap SEO .. Show Free Ship + Modules .. Specials by Category for SPPC .. Store Mode (open|closed|maintenance) .. Store Pickup Shipping .. Theme Switcher .. Ultimate SEO URLs 5 Pro .. UPS XML Rates & Svcs 1.4 .. USPS methods 7.3.1 .. Who's Online Dashboard . Fixes: Add to cart -> 'product not found' : FIX Login issues with IE 11 : FIX Tools: Incredibly Handy: osC Xref
♥kymation Posted January 7, 2014 Posted January 7, 2014 for( $index=[font=arial,helvetica,sans-serif]123500[/font]; $index < [font=arial,helvetica,sans-serif]123995[/font]; $index+=5 ) { print $index . '<br>'; } That will list all of the model numbers in the range you stated, incremented by 5. Now replace the print statement with whatever you want to do with those numbers. Regards Jim See my profile for a list of my addons and ways to get support.
Supertex Posted January 8, 2014 Author Posted January 8, 2014 Thank you for the reply. I do not need to list the numbers, I need to write them to the DB. I'm not a coder, but I'm learning as I go. Perhaps look at this point out my mistakes. For instance, I'm assuming "$row" will always start at "1" or is it defined another way? I'm not sure of any of this, but I hope it's headed in the right direction, at least. Currently, I get "Parse error: syntax error, unexpected '}' in /blah/blah/skuset.php on line 15 <?php $cat = "414"; //edit for category selection $inc = "5"; //edit for increment $r_start = "123500"; //edit for starting sku# $r_end = "123995"; //edit for ending sku# $mysqli = new mysqli("dbaddress", "dbuser", "dbpass", "dbname"); /*--edit for db access--*/ if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ")" . $mysqli->connect_error; } $res = $mysqli->query("SELECT products_id, products_sort_order, products_model FROM products WHERE products_id IN (SELECT products_id FROM products_to_categories WHERE categories_id='". $cat ."' ORDER BY products_sort_order"); if ($row = 1) { $sku=($r_start) } else {$sku=((($row) * ($inc)+($r_start)) } if ($sku <= $r_end){ (!$mysqli->query("UPDATE products SET products_model = '". $sku ."' WHERE products_id = '". $row['products_id'] ."' LIMIT 1")) { echo "MySQL Error: (" . $mysqli->errno . ") " . $mysqli->error; echo "Updated Product #: <b>". $row['products_name'] ."</b><br />\n\tOld SKU: ". $row['products_model'] ."<br />\n\tNew Model: ". $new_name ."<br />\n"; } else { echo "Operations Complete", die } ?> osC v2.3.1 MySQL v8.0.32 PHP v5.6.40 Installed addons: . Attribute Sets Plus .. Create Account & Manual Order Maker .. Customer Testimonials 2.3.4 .. Customer Blacklist .. Dynamic Info Pages .. FedEx Web Svcs v9 .. Filtered Sales Report .. Generic Box .. Google XML Sitemap SEO .. Maximum Order Value .. Modular Front Page .. Monthly Sales & Tax Report .. Multiple Products Manager .. Must Accept Terms & Conditions .. Order Editior .. PDF Customer Invoice .. Price in Cart Only .. Product Sort/Order .. Product Sort in Cart .. Quantity Discounts .. Restrict Delivery Methods .. SEO Header Tags - Reloaded .. Separate Pricing Per Customer .. Simpler Admin Session Length Control .. Sitemap SEO .. Show Free Ship + Modules .. Specials by Category for SPPC .. Store Mode (open|closed|maintenance) .. Store Pickup Shipping .. Theme Switcher .. Ultimate SEO URLs 5 Pro .. UPS XML Rates & Svcs 1.4 .. USPS methods 7.3.1 .. Who's Online Dashboard . Fixes: Add to cart -> 'product not found' : FIX Login issues with IE 11 : FIX Tools: Incredibly Handy: osC Xref
♥kymation Posted January 8, 2014 Posted January 8, 2014 Your first query is going to be slow. You should always use JOIN instead of the included select when possible, as it is here. if ($row = 1) { sets the value of $row to one. You want $row == 1 for a test. In any case, that test will always fail because you haven't defined $row anywhere. Did you mean that as $row = $res->fetch_row();? If you did, the test is wrong, since $row is an array. Line 15 needs to be $sku = $r_start; If you are going to be including this code in an osCommerce page, you need to use the tep_db_ functions instead of the PHP mysqli() class. Failure to do this will result in broken code at some future point, like it just did with osC 2.3.3.4. I don't see anything else right now. Regards Jim See my profile for a list of my addons and ways to get support.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.