Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need php expert


patator

Recommended Posts

Sorry to post again this question, but I'm really, really stuck :

 

Hello

 

I'm kind of dummy with php and I try to make relationships between attributes.

 

I added 2 boolean fields to the Products_Attribute table : "RIGHT_HAND", "LEFT_HAND"

 

 

To the "new_attribute_include" file, I added two check boxes to indicate, for a selected attribute, if it is available for RIGHT_HAND and/or LEFT_HAND :

 

if ($attribute_RH == "-1") {                       
    echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_RH[]\" value=\"" .$attribute_RH . "\"" . $CHECKED . ">  </TD>";
    }else {
    echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_RH[]\" value=\"" . $attribute_RH . "\">  </TD>";
    }


    if ($attribute_LH == "-1") {                       
    echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_LH[]\" value=\"" . $attribute_LH . "\"" . $CHECKED . ">  </TD>";
    }else {
    echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_LH[]\" value=\"" . $attribute_LH . "\">  </TD>";
    }

When I edit (from the admin edition option) a product with Righ_Hand set to "-1" (entered manually in the table), I can see it is correctly ticked next to the related attribute (ie : loft of 15?)

 

Now comes my problem, if I tick RH or LH boxes and click on save, it doesn't save my selection. I'm sure it has sthg to do with the $HTTP_POST_VARS in the new_attribute_change.php, here is what I added to the file :

 

$value_RH = $HTTP_POST_VARS[$optionValues[$i] . '_optionValues_RH'];
$value_LH = $HTTP_POST_VARS[$optionValues[$i] . '_optionValues_LH'];
.....
      MYSQL_QUERY( "INSERT INTO products_attributes ( products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order,RH,LH)
                   VALUES( '$current_product_id', '$optionsID', '$optionValues[$i]', '$value_price', '$value_prefix', '$value_sort','$value_RH','$value_LH')" ) or die(mysql_error());
.......

 

I'm sure I'm missing shtg, because I don't really know how works a checkbox in php.

 

I really, really hope a proper developper could have a look at my post and try to help me.

Thanks

Patrice

Link to comment
Share on other sites

Sorry to rebump again, but I'm getting crazy with this check box.

I can't figure out what to do, I've been trying plenty of options and no luck....

 

Please somebody help me please

patisdesperateforananswer

 

Sorry to post again this question, but I'm really, really stuck :

 

Hello

 

I'm kind of dummy with php and I try to make relationships between attributes.

 

I added 2 boolean fields to the Products_Attribute table : "RIGHT_HAND", "LEFT_HAND"

To the "new_attribute_include" file, I added two check boxes to indicate, for a selected attribute, if it is available for RIGHT_HAND and/or LEFT_HAND :

 

if ($attribute_RH == "-1") { ? ? ? ? ? ? ? ? ? ? ? 
? ? echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_RH[]\" value=\"" .$attribute_RH . "\"" . $CHECKED . ">  </TD>";
? ? }else {
? ? echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_RH[]\" value=\"" . $attribute_RH . "\">  </TD>";
? ? }
? ? if ($attribute_LH == "-1") { ? ? ? ? ? ? ? ? ? ? ? 
? ? echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_LH[]\" value=\"" . $attribute_LH . "\"" . $CHECKED . ">  </TD>";
? ? }else {
? ? echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_optionValues_LH[]\" value=\"" . $attribute_LH . "\">  </TD>";
? ? }

When I edit (from the admin edition option) a product with Righ_Hand set to "-1" (entered manually in the table), I can see it is correctly ticked next to the related attribute (ie : loft of 15?)

 

Now comes my problem, if I tick RH or LH boxes and click on save, it doesn't save my selection. I'm sure it has sthg to do with the $HTTP_POST_VARS in the new_attribute_change.php, here is what I added to the file :

 

$value_RH = $HTTP_POST_VARS[$optionValues[$i] . '_optionValues_RH'];
$value_LH = $HTTP_POST_VARS[$optionValues[$i] . '_optionValues_LH'];
.....
? ? ? MYSQL_QUERY( "INSERT INTO products_attributes ( products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order,RH,LH)
? ? ? ? ? ? ? ? ? ?VALUES( '$current_product_id', '$optionsID', '$optionValues[$i]', '$value_price', '$value_prefix', '$value_sort','$value_RH','$value_LH')" ) or die(mysql_error());
.......

 

I'm sure I'm missing shtg, because I don't really know how works a checkbox in php.

 

I really, really hope a proper developper could have a look at my post and try to help me.

Thanks

Patrice

Link to comment
Share on other sites

It's getting better, I change the checkbox to an input box and I manage to save the captured data in the table.

 

I had to add one function to the new_attribute_function.php :

// Get RH LH values based on Linda Contrib
function getHandValues( $current_value_id, $current_product_id )
{
global $attribute_RH, $attribute_LH,$isSelected;

if ( $isSelected ) {
                  	 
       $query = "SELECT * FROM products_attributes where options_values_id = '$current_value_id' AND products_id = '$current_product_id'";

       $result = mysql_query($query) or die(mysql_error());

       while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                              	 
               $attribute_RH = $line['RH'];
               $attribute_LH = $line['LH'];
              
       }
       
} else {
      	 
   $attribute_RH = '';
               $attribute_LH = '';
}

}

 

Into new_attribute_include.php, I have :

getHandValues( $current_value_id, $current_product_id );
echo "<TD class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_RH\" value=\"" . $attribute_RH . "\" size=\"4\"></TD>";

 

In new attribute_change.php, I have now :

$value_RH = $HTTP_POST_VARS[$optionValues[$i] . '_RH'];

MYSQL_QUERY( "INSERT INTO products_attributes ( products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order,RH,LH)
                    VALUES( '$current_product_id', '$optionsID', '$optionValues[$i]', '$value_price', '$value_prefix', '$value_sort','$value_RH','$value_LH')" ) or die(mysql_error());

 

So, can somebody tell me how to use a checkbox instead of the input box ?

 

 

Thanks, thanks for the person who is going to help me :thumbsup:

Link to comment
Share on other sites

RE-re-re-bump, I'm sorry but I really need some help. I just want to know how can I use a checkbox instead of my input box in the following files :

 

Thanks for your time.

 

It's getting better, I change the checkbox to an input box and I manage to save the captured data in the product_attribute table.

 

I had to add one function to the new_attribute_function.php :

// Get RH LH values based on Linda Contrib
function getHandValues( $current_value_id, $current_product_id )
{
global $attribute_RH, $attribute_LH,$isSelected;

if ( $isSelected ) {
? ? ? ? ? ? ? ? ? ?	
? ? ? ?$query = "SELECT * FROM products_attributes where options_values_id = '$current_value_id' AND products_id = '$current_product_id'";

? ? ? ?$result = mysql_query($query) or die(mysql_error());

? ? ? ?while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	
? ? ? ? ? ? ? ?$attribute_RH = $line['RH'];
? ? ? ? ? ? ? ?$attribute_LH = $line['LH'];
? ? ? ? ? ? ? 
? ? ? ?}
? ? ? ?
} else {
? ? ? ?	
? ?$attribute_RH = '';
? ? ? ? ? ? ? ?$attribute_LH = '';
}

}

 

Into new_attribute_include.php, I have :

getHandValues( $current_value_id, $current_product_id );
echo "<TD class=\"main\" align=\"left\"><input type=\"text\" name=\"" . $current_value_id . "_RH\" value=\"" . $attribute_RH . "\" size=\"4\"></TD>";

 

In new attribute_change.php, I have now :

$value_RH = $HTTP_POST_VARS[$optionValues[$i] . '_RH'];

MYSQL_QUERY( "INSERT INTO products_attributes ( products_id, options_id, options_values_id, options_values_price, price_prefix, products_options_sort_order,RH,LH)
? ? ? ? ? ? ? ? ? ? VALUES( '$current_product_id', '$optionsID', '$optionValues[$i]', '$value_price', '$value_prefix', '$value_sort','$value_RH','$value_LH')" ) or die(mysql_error());

 

So, can somebody tell me how to use a checkbox instead of the input box ?

Thanks, thanks for the person who is going to help me :thumbsup:

Link to comment
Share on other sites

Here is the final answer :

in new_attributes_function.php

function getHandValues( $current_value_id, $current_product_id )
{
global $attribute_RH, $attribute_LH,$isSelected;

if ( $isSelected ) {
                  	 
       $query = "SELECT * FROM products_attributes where options_values_id = '$current_value_id' AND products_id = '$current_product_id'";

       $result = mysql_query($query) or die(mysql_error());

       while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                              	 
               $attribute_RH = $line['RH'];
               $attribute_LH = $line['LH'];
              
       }
       
} else {
      	 
   $attribute_RH = '';
               $attribute_LH = '';
}

}

 

In new_attributes_include

getHandValues( $current_value_id, $current_product_id );

 if ($attribute_RH == "1") {
     echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_RH\"  value=\"1\"" . $CHECKED . ">  </TD>";
     }else {
     echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_RH\"  value=\"1\">  </TD>";
     }

if ($attribute_LH == "1") {
     echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_LH\"  value=\"1\"" . $CHECKED . ">  </TD>";
     }else {
     echo "<TD class=\"main\" align=\"left\"><input type=\"checkbox\" name=\"" . $current_value_id . "_LH\"  value=\"1\">  </TD>";
     }

 

In new_attributes_change

$value_RH = $HTTP_POST_VARS[$optionValues[$i] . '_RH'][0];
   $value_LH = $HTTP_POST_VARS[$optionValues[$i] . '_LH'][0];

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...