Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

set field=(numeric range) by (increment)


Supertex

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...