Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

need help with making php mysql code ....


teksigns

Recommended Posts

im trying to figure out how to make a line of code

to update the product status of all products in a particular

catagorie.

 

 

help !!!!!!!!!!!!!!!!!!!!!!

 

 

function tep_set_categories_status($categories_id, $status) {

   switch (true){

case ($status == '1'):

     return tep_db_query("update " . TABLE_CATEGORIES . " set categories_status = '1' where categories_id = '" . $categories_id . "'");

break;

case ($status == '0'):

// I NEED THE CODE FOR MYSQL UPDATE TO BE HERE.

     return tep_db_query("update " . TABLE_CATEGORIES . " set categories_status = '0' where categories_id = '" . $categories_id . "'");

break;

default:

     return -1;

   }

 }

 

 

as you can see the line that sets the catagorie status is already returning

a update statement . however i need that line to also include a update

to all products in the catagorie and set there product status to "2" .

 

 

how can i do this

 

 

i only need this for the line with:

 

 

 

 

// I NEED THE CODE FOR MYSQL UPDATE TO BE HERE.

 

 

NOTE:

i only want all product status set to 2 in the disabled directory

for the products with status thats not equal to "0"

 

 

anyone help me out with this .....

 

i know its possible i just dont know how yet.

Link to comment
Share on other sites

I don't think you can use update with two set statements separated by an AND, which it sounds like you want. Maybe I just don't understand you correctly, but what I think you want is something like

 

set category_status = x where blah AND set category_status = y where blah".

 

Is this sort of what you're looking for?

 

-j

Link to comment
Share on other sites

same problem i was having before asking for help .

 

 

1054 - Unknown column 'categories_id' in 'where clause'

 

update products set products_status='2' where categories_id = '164' and products_status != '0'

 

[TEP STOP]

 

 

 

 

since categories_id is not located in the products table

it gives a error.

 

 

 

how to do this ?

Link to comment
Share on other sites

Ah. That's a little sticky. You'll have to reference the products_to_category table (I think that exists...if not, it's similar something like that) in a fashion like:

 

WHERE products_to_category.category_id=x AND products_to_category.product_id=products.product_id AND products.product_status=y

 

 

I pulled that from my head without looking at any of the tables. If that still doesn't work, it's something similar to that. You just have to reference the ptc table as well, that's all.

 

-j

Link to comment
Share on other sites

i came up with this code

 

 

$products2_query = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . $categories_id . "'");

while ($product_incat = tep_db_fetch_array($products2_query)) {

   tep_db_query("update products set products_status='2' where products_id = '" . $product_incat['products_id'] . "' and products_status != '0'");

   }

 

 

 

do you see anything wrong with it that could cause problems.

 

 

it seems to be working although i dont know if it might be hurting something else in the database.....

 

 

thanks for your input and guiding me in the correct direction .

Link to comment
Share on other sites

opps just run into a snag....

 

 

when the catagorie contains no products

but it contains sub catagories with products

in them it does not update those products

in the sub catagories....

 

 

what kind of code do i need to add to do this .....?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...