1Putts Posted June 19, 2010 Posted June 19, 2010 This shouldn't be too difficult but for some reason I can't get the syntax quite right. I'm trying to merge these two statements together into one so that it adds both the sort order (attributes_sort) and hide from groups (@) to the database. Here are the two statements: tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '@')"); tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '" . (int)$attributes_sort . "')"); I need the "@" to be the last item inserted. My efforts have resulted in it just adding "NULL" instead of the "@" and, as a result, the product attributes don't show up. Thanks in advance for any help. Quote
Jan Zonjee Posted June 19, 2010 Posted June 19, 2010 I need the "@" to be the last item inserted. My efforts have resulted in it just adding "NULL" instead of the "@" and, as a result, the product attributes don't show up. Possibly the field attributes_hide_from_groups is not in the place where it should be using the sequence of values you use in the insert query. If could be before or after the field added for attributes sort. The safest route is to explicitly name the order of fields first like in this example: insert into products_attributes (products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix, attributes_hide_from_groups) values (null, '1', '4', '2', '50.0000', '+', '@'); Quote
1Putts Posted June 20, 2010 Author Posted June 20, 2010 Possibly the field attributes_hide_from_groups is not in the place where it should be using the sequence of values you use in the insert query. If could be before or after the field added for attributes sort. The safest route is to explicitly name the order of fields first like in this example: insert into products_attributes (products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix, attributes_hide_from_groups) values (null, '1', '4', '2', '50.0000', '+', '@'); Thanks Jan. I have the the right number of fields all set up and in the correct order. I've tried merging those two statements together and I'm probably just not getting the syntax just right. Everything is right except the last field which ends up being "NULL" instead of "@". So I'm just looking for the correct syntax. For example, this is what I have now and it's apparently not right: tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '" . (int)$attributes_sort . "' '@')"); Quote
Jan Zonjee Posted June 20, 2010 Posted June 20, 2010 I have the the right number of fields all set up and in the correct order. Looks like there is a comma missing between '" . (int)$attributes_sort . "' and '@' tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '" . (int)$attributes_sort . "' '@')"); Quote
1Putts Posted June 20, 2010 Author Posted June 20, 2010 Looks like there is a comma missing between '" . (int)$attributes_sort . "' and '@' tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '" . (int)$attributes_sort . "' '@')"); OK, here's my latest attempt but still no luck: tep_db_query("insert into " . TABLE_PRODUCTS_ATTRIBUTES . " values (null, '" . (int)$products_id . "', '" . (int)$options_id . "', '" . (int)$values_id . "', '" . (float)tep_db_input($value_price) . "', '" . tep_db_input($price_prefix) . "', '" . (int)$attributes_sort . "', '@')"); Is it necessary to have the (null, at the beginning of the statement? Maybe that's what is throwing if off... Quote
Jan Zonjee Posted June 20, 2010 Posted June 20, 2010 Is it necessary to have the (null, at the beginning of the statement? Maybe that's what is throwing if off... The null is for the auto incrementing value of products_attributes_id. Using '' might work, might throw an error too. Everything seems in the correct order (provided attributes_sort is the only field added and added before attributes_hide_from_groups): products_attributes_id -> null products_id -> (int)$products_id options_id -> (int)$options_id options_values_id -> (int)$values_id options_values_price -> (float)tep_db_input($value_price) price_prefix -> tep_db_input($price_prefix) attributes_sort -> (int)$attributes_sort attributes_hide_from_groups -> @ Quote
1Putts Posted June 21, 2010 Author Posted June 21, 2010 The null is for the auto incrementing value of products_attributes_id. Using '' might work, might throw an error too. Everything seems in the correct order (provided attributes_sort is the only field added and added before attributes_hide_from_groups): products_attributes_id -> null products_id -> (int)$products_id options_id -> (int)$options_id options_values_id -> (int)$values_id options_values_price -> (float)tep_db_input($value_price) price_prefix -> tep_db_input($price_prefix) attributes_sort -> (int)$attributes_sort attributes_hide_from_groups -> @ Thanks again, Jan. Mystery solved...there was in fact another similar query that needed to be modified as well. It's the one that "clones" product attributes...so here's the new one in case anyone is doing something similar: tep_db_query("INSERT INTO " . TABLE_PRODUCTS_ATTRIBUTES . " ( products_id, options_id, options_values_id, options_values_price, price_prefix, attribute_sort, attributes_hide_from_groups) VALUES (".$clone_product_id_to.", ".$attributes_values['options_id'].", ".$attributes_values['options_values_id'].", ".$attributes_values['options_values_price'].", '".$attributes_values['price_prefix']."' , ".$attributes_values['attribute_sort'].", '@')"); Quote
1Putts Posted June 21, 2010 Author Posted June 21, 2010 The null is for the auto incrementing value of products_attributes_id. Using '' might work, might throw an error too. Everything seems in the correct order (provided attributes_sort is the only field added and added before attributes_hide_from_groups): products_attributes_id -> null products_id -> (int)$products_id options_id -> (int)$options_id options_values_id -> (int)$values_id options_values_price -> (float)tep_db_input($value_price) price_prefix -> tep_db_input($price_prefix) attributes_sort -> (int)$attributes_sort attributes_hide_from_groups -> @ Thanks again, Jan. Mystery solved...there was in fact another similar query that needed to be modified as well. It's the one that "clones" product attributes...so here's the new one in case anyone is doing something similar: tep_db_query("INSERT INTO " . TABLE_PRODUCTS_ATTRIBUTES . " ( products_id, options_id, options_values_id, options_values_price, price_prefix, attribute_sort, attributes_hide_from_groups) VALUES (".$clone_product_id_to.", ".$attributes_values['options_id'].", ".$attributes_values['options_values_id'].", ".$attributes_values['options_values_price'].", '".$attributes_values['price_prefix']."' , ".$attributes_values['attribute_sort'].", '@')"); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.