Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with mySQL!


Guest

Recommended Posts

I need to create a "products_weight" column in the "orders_products" table, and fill it with the appropriate weights drawn from the "products" table.

 

What would be the syntax for this?

Link to comment
Share on other sites

Why not just grab the information from the table that already has the information in it?

Wendy James

 

Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.

Link to comment
Share on other sites

I agree with Wendy...just use the existing data.

 

Bobby

 

OK, let me back up and explain myself so you guys can tell me what I need to learn. :)

 

In my invoice, I need the products to be ordered by weight (don't ask). The code that grabs the product information for the order appears to be this, located in /admin/includes/classes/order.php:

 

      $orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");

 

So, I was thinking that if this table ("orders_products") had a products_weight column, with the appropriate weights pulled from the "products" table, then I could just add "order by products_weight" to this query and that would do the trick.

 

Does that make sense, or is there a better way to do it? Either way, I'm looking for the actual syntax... :)

 

Thanks!

Link to comment
Share on other sites

$orders_products_query = tep_db_query('SELECT OP.orders_products_id, OP.products_name, OP.products_model, OP.products_price, OP.products_tax, OP.products_quantity, OP.final_price FROM' . TABLE_ORDERS_PRODUCTS . ' OP JOIN ' . TABLE_PRODUCTS . ' P ON OP.products_id=P.products_id WHERE orders_id = ' . (int)$order_id . ' ORDER BY P.products_weight');

 

Or Descending by weight (same with DESC on the end!)

 

$orders_products_query = tep_db_query('SELECT OP.orders_products_id, OP.products_name, OP.products_model, OP.products_price, OP.products_tax, OP.products_quantity, OP.final_price FROM' . TABLE_ORDERS_PRODUCTS . ' OP JOIN ' . TABLE_PRODUCTS . ' P ON OP.products_id=P.products_id WHERE orders_id = ' . (int)$order_id . ' ORDER BY P.products_weight DESC');

Link to comment
Share on other sites

Since you can have really long signatures these days, might as well start a webring LOL

"This guy/girl knows osC and MySQL", if you link to the osC user name, you're not doing anything wrong haha

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...