is ELSE the right choice?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: is ELSE the right choice?

Post 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']) . ";");
    }
      }
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: is ELSE the right choice?

Post 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?
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: is ELSE the right choice?

Post 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?
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: is ELSE the right choice?

Post 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 ;)
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: is ELSE the right choice?

Post 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...
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: is ELSE the right choice?

Post 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) . ";");
    }
Post Reply