Page 2 of 2
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 6:04 pm
by jeremybass
would anybody know if i'm on the right track now... i was total over looking the == thing again ... i though i fixed that after it was pointed out lol... oh well
here is the lastest
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$check_msg = "Checked: $val\n";
if ($check_msg = $val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " . tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
else {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE NOT extra_fields_type_id=" . tep_db_input($key) . " AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 6:43 pm
by John Cartwright
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
check_msg = "Checked: $val\n";
if ($check_msg = $val) {
Like you have pointed out you simply don't understand the simple language contructs, which is why your having so many problems modifying this code.
Lets start simple. I assume that the array $HTTP_POST_VARS['mark'] (it should be $_POST['mark'], by the way) is the group of checkbox html elements. Is this correct?
If so, you will only ever get the value of the checkboxes that have been checked. So if you do not check a particular checkbox it will not be represented in the $_POST superglobal. So if you have the value in your array thats how to determine if the checkbox has been checked or not.
Everything clear so far?
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 6:49 pm
by jeremybass
i think i'm clear, is i can't dirtecly tell if it's not checked... i must tell by way off what is checked?
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 6:53 pm
by jeremybass
yep i'm cystal clear...
check it out...
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " . tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE NOT extra_fields_type_id=" . tep_db_input($key) . " AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}

thank you i know i'll be back but sharper

Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 7:04 pm
by jeremybass
damn i got all excited for nothing... now it just does one or the other... i think i'm on the right path...
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 7:24 pm
by jeremybass
Now i got it.... but i had to add a check box the was none so one would have to select None to have none... with a valadation script i think this is close enough... an ideas on it are welcomed... thank for all the help...
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE NOT extra_fields_type_id=" . tep_db_input($key) . " AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE NOT extra_fields_type_id=0 AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " . tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}