Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

writing in new table in database...


paulchen2005

Recommended Posts

Hello,

 

i have some (not all) article with slave and i use the contrib artikelgroesse.

 

if i have a slave article the number of the master is 0.

Now i need a addition from the number of masterartikel with all slave article to show the correct ampel in the product listing...

 

i write a new line in my SQL database, the name is allslave. With this field i will show the ampel

 

now i need a code to add the slave article into the field allslave into the SQL database...

 

and i need a code to cancel the slave article from the field allslave from the SQL database if someone buy something...

 

 

can someone help me to write the code ???

 

 

thank you very much

Paul

 

 

p.s.: sorry for my bad english, i hope you can understand me...

Link to comment
Share on other sites

now i need a code to add the slave article into the field allslave into the SQL database...

 

and i need a code to cancel the slave article from the field allslave from the SQL database if someone buy

On what table did you add the field allslave?

 

What exactly is the data that is supposed to go into allslave? I'm not sure what "ampel" is.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

thank you for answer and sorry for some german word,

 

with "ampel" i mean traffic light, i have a picture in my product list that shows how much article is available (or not available) it shows red, halfred, orange, half orange, green and half green

 

 

but the traffic light only works with master products,

 

if i have now some slave products is the number of master articles zero but i need it to show the traffic light...

 

 

so i think i add all slaves with the master and use the result to show my traffic light, for this idea have i write a new line in my SQL database with the name "allslave".

 

now i must add all slave articles in thes new line in database...

 

bsp.

if i add in admin menue a new product with 10 master article, so write the programm write now in the SQL database quantity +10, but it must at the same time add in in my new line "allslave".

(Quantity Master Article +10 and quantity allslave +10 )

 

and the same must it write if i add a slave article in admin menue, the numbers of articles must at the same time add in in my new line "allslave".

(Quantity slave article +15 and quantity allslave +15)

 

is that correct can i show the traffic light in the product list with the data from my new line allslave...

 

do you mean what i need ?

 

i need a code to add the number of allslave in the SQL database, it is the same code to add the number of qty articles but i have no idea wich code it is...

 

 

thank you for help,

 

Paul

Link to comment
Share on other sites

Please show me the database structure you have so I can see what it looks like. It looks like I need to see the products table. Did you add the allslave field to the products table?

 

yes, in the table products, i add the field with the command:

ALTER TABLE products ADD products_allslave CHAR(5) NOT NULL default '';

 

it ist the same table to save the products_quantity from the master article

 

but now i want to save the sum of all slave articles too to show the traffic light in the product list with this one

Link to comment
Share on other sites

ok,

 

1vp6.jpg

 

1. in Admin menue, blue is my Master article, quantity is 0 the red one is the slave article, the quantity is 10 for both

 

2. the product list, this traffic light must show the complete quantity (master and all slave article, but the number of slave article is different, it change between 2 - open end)

 

3. the product info, the traffic light from the slave article is correct and here must the quantity from all slave article add to the quantity from the master too...

 

 

my php is not good, my english is better, so i hope someone can help me with the code...

Link to comment
Share on other sites

So if:

 

Slave 1: 10

Slave 2: 12

 

Master should be 22? Or 10?

=22

 

When you sell 1 product, what should the resulting stock be?

 

Slave 1: 9

Slave 2: 11

Master: 21

 

or

 

Slave 1: 9

Slave 2: 11

Master: 9

 

if i have

Slave 1: 9

Slave 2: 11

is it together 20,

 

if i sell 1 product from slave1 is the result slave1=8 and together =19

Link to comment
Share on other sites

I understand what you want, but the version I downloaded doesn't seem to do Master/Slave. Can you send me the code you have for admin/categories.php? Also, can you give me the entire structure for your products table? I need to see how the relationship between master and slave is stored. Is there another table that tracks that?

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

can i use the sum function from php to add the master article with all slave articles w/o write in new table field?

 

i must add all products_quantity from same products_family name

 

see my table on picture

 

1cm1.jpg

 

the products_id 28 is the Master, the products_id 32 and 33 are the slave article

 

 

you see if i had a slavearticle they have the same name in products_family.

 

now i must sum all products_quantity from same products_family.

 

 

how must look code?

 

can someone help me please ?

Link to comment
Share on other sites

I don't understand how you get the master/slave relationship - I don't seem to have that ability in the download you pointed me to. You don't want to just sum the quantities, because you need to know whether you're viewing a slave or a master. If you're viewing a master, sum all slave quantities. If you're viewing a slave, just show the quantity from the database table. Correct?

 

So, I need to know how a "MASTER" is defined. How do you know which products are masters?

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

please ignore master and slave,

 

i want to add all products_quantity with same name in products_family,

 

the name in picture from products_family you see is "dekorative H"

 

so i must add 0+15+9 =24

 

for automatic calculate sum i search a formel

 

i found

$add = tep_db_query("select sum(products_quantity) from products where products_family='dekorative H'");

 

in my sql database i tested it and the result is correct

 

but echo $add shows Resource id #120

 

 

the next problem is

where products_family='dekorative H'

"dekorative H" is a change attrib in the table, can i write

where products_family='$products_family'

or what can i do ?

 

because this formel must sum all same names in products_family...

 

with the sum of all articles in same product_family i will show the traffic light

 

------------------------------

later i use the if function,

 

if some name in products_family(products_Id) show the traffic light with count from $add (the sum of all products_quantity with same name in products_family)

 

else show traffic light with count from products_quantity

Link to comment
Share on other sites

Start small:

 

$add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='dekorative H'");
$add_result = tep_db_fetch_array($add);
echo $add_result['true_qty'];

 

Yes, that is it !!!

 

thanks, but now the next one:

 

what can i write to sum all products_quantity from the same name in products_family from the product what i look

 

this code i must change

where products_family='dekorative H'

 

???

Link to comment
Share on other sites

Try this:

 

$add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$product_family['products_family']."'");
$add_result = tep_db_fetch_array($add);
echo $add_result['true_qty'];

 

 

IT IS PERFECT

 

thanks, thanks, thanks :D :D :D

 

that is what i need,

 

many thanks

 

i am so happy

Link to comment
Share on other sites

Hi,

 

i have a new question...

in product_info works this code perfect... :)

 

 

because in includes/product_listing.php...

 

this code show a picture from quantity and show how many master article i have from the product

<?php echo ?><br><?php echo '<a href="java script:Popup()">'. picto_qty($listing_values['products_quantity']) . ''; echo $listing_values['products_quantity'];
?>

i change it with this code

<?php							
$add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$product_family['products_family']."'");
$add_result = tep_db_fetch_array($add);
echo $add_result['true_qty'];
?>

 

 

I want to show in that list all quantity from the all products with same name in product_familie

 

but the code shows all quantity from all products i have <_<

 

 

what must i do to show all quantity from same product_family in the product listing ?

Link to comment
Share on other sites

Hi,

 

sorry but it is to late for edit...

 

 

this one does not go too

<?php							
$add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$listing_values['products_family']."'");
$add_result = tep_db_fetch_array($add);
echo $add_result['true_qty'];
?>

 

here is the error:

where products_family='".$products_family['products_family']."'")

 

because

where products_family='dekorative H'

show in my list the quantity from all products who has 'dekorative H' in products_family

 

 

now i search for the correct where products_family= ?

Link to comment
Share on other sites

includes/modules/product_listing.php is called from index.php line 280:

 

		<td><?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING); ?></td>

 

product_info.php has this query at the top (line 27-28):

 

		$product_family_query = tep_db_query("select p.products_id, p.products_family from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
 $product_family = tep_db_fetch_array($product_family_query);</td>

 

The above query is where the products_family information comes from. This query does not exist in index.php, so we can't know what the family is. You'll need to add this query to the index.php before it includes product_listing.php.

 

index.php line 260-217:

 

// Get the right image for the top-right
$image = DIR_WS_IMAGES . 'table_background_list.gif';
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
  $image = tep_db_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
  $image = tep_db_fetch_array($image);
  $image = $image['manufacturers_image'];
} elseif ($current_category_id) {
  $image = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
  $image = tep_db_fetch_array($image);
  $image = $image['categories_image'];
}
?>

 

Add the products_family query after this so that the code looks like:

 

// Get the right image for the top-right
$image = DIR_WS_IMAGES . 'table_background_list.gif';
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
  $image = tep_db_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
  $image = tep_db_fetch_array($image);
  $image = $image['manufacturers_image'];
} elseif ($current_category_id) {
  $image = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
  $image = tep_db_fetch_array($image);
  $image = $image['categories_image'];
}
$product_family_query = tep_db_query("select p.products_id, p.products_family from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
$product_family = tep_db_fetch_array($product_family_query);
?>

 

Then you can make the change in includes/product_listing.php:

 

<br>
<?php 
 $add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$product_family['products_family']."'");
 $add_result = tep_db_fetch_array($add);
 echo '<a href="java script:Popup()">'. picto_qty($add_result['true_qty']) . ''; 
 echo $add_result['true_qty'];
?>

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

i have added "p.products_family" in index.php

 

in 4 lines with

$listing_sql = "select " . $select_column_list . "

 

change

where products_family='".$product_family['products_family']."'");

in

where products_family='".$listing_values['products_family']."'");

 

and it works fine !!!

 

 

thank you for help me, i want to check it tonight if your code is better

Link to comment
Share on other sites

Hi,

 

i have added "p.products_family" in index.php

 

in 4 lines with

$listing_sql = "select " . $select_column_list . "

 

change

where products_family='".$product_family['products_family']."'");

in

where products_family='".$listing_values['products_family']."'");

 

and it works fine !!!

thank you for help me, i want to check it tonight if your code is better

 

 

This method works perfectly fine and is in fact better (as it reduces the number of queries needed).

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

ok, thank you

 

now I have still one if query before the formula written because not every article has an entry in product_family

 

example:

 

if the field in product_famliy empty so use the sum function to add all quantity from same product_family else show the quantity from products_quantity

 

if ($....['products_family']!='') {
....
} else {
...
}

 

 

i am so happy :D !!!!

 

thank you kgt :D !!!

 

and sorry for my bad english... :D

Link to comment
Share on other sites

For product_info.php line 95-96:

 

  $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 $product_info = tep_db_fetch_array($product_info_query);

 

Add the following after:

 

if( $products_family['products_family'] != '' ) {
 $add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$product_family['products_family']."'");
 $add_result = tep_db_fetch_array($add);
 $product_info['products_quantity'] = $add_result['true_qty'];
}

 

So it looks like:

 

  $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 $product_info = tep_db_fetch_array($product_info_query);
 if( $products_family['products_family'] != '' ) {
$add = tep_db_query("select sum(products_quantity) as true_qty from products where products_family='".$product_family['products_family']."'");
$add_result = tep_db_fetch_array($add);
$product_info['products_quantity'] = $add_result['true_qty'];
 }

 

Then when displaying the quantity, you only need to use

 

echo $product_info['products_quantity'];

 

and it will always be correct.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...