Jump to content
Sign in to follow this  
1Putts

Help merging these two statements

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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', '+', '@');

Share this post


Link to post
Share on other sites

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 . "' '@')");

Share this post


Link to post
Share on other sites

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 . "' '@')");

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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 -> @

Share this post


Link to post
Share on other sites

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'].", '@')");

Share this post


Link to post
Share on other sites

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'].", '@')");

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×