0

hi am having this trouble trying to save in multiple rows in the table "notification" with a for of customers table ids but it only save me one row this is my code:

  $customers = tep_get_customers();
  $count = 0;
for ($i=0, $n=sizeof($customers); $i<$n; $i++) {
    $count ++;
$insert_str_cony .= $customers[$i]['id'];
$split_customers_id = explode("||", $insert_str_cony.'||', -1);
$values .= "('','" . tep_db_input('1') . "', now(), '" . tep_db_input($products_id) . "', '" . tep_db_input($split_customers_id[$count]) . "'),";
$db_values = substr_replace($values, '', -1, 1);
}
              if ($action == 'insert_product') { 
                tep_db_query("insert into notifications (notify_id, prod_notify, notify_added, prod_id, customers_id) values ". $db_values);  
                 } elseif ($action == 'update_product') { 
              tep_db_query("update notifications set prod_notify = '" . tep_db_input('1mod') . "', notify_last_mod = now(), prod_id = '" . $HTTP_GET_VARS['pID'] . "', customers_id = '" . tep_db_input($customers['customers_id']) . "'"); 
          }

and this is the function tep_get_customers();

  function tep_get_customers() {
   $customers_query = tep_db_query("select distinct customers_id from " . TABLE_CUSTOMERS . "");
    while ($customers = tep_db_fetch_array($customers_query)) {
      $customers_array[] = array('id' => '||'.$customers['customers_id']);
    }

    return $customers_array;
  }

plase need help!!! thanks!

2
  • echo $db_values and show the result. Also, provide tep_db_query Commented Nov 28, 2011 at 7:05
  • i think problem in for loop end } put it below if condition Commented Nov 28, 2011 at 7:45

1 Answer 1

2

That is because Insert + values insert one row in the database . (You can use Insert with a SELECT query to insert multiple rows using Insert command but that's not your case as I can see ). Therefore you should provide a script containing multiple insert commands (an insert command for each customer) in order to insert multiple rows into the database.

Sign up to request clarification or add additional context in comments.

1 Comment

Ha, i missed that they closed their for loop. I thought they were still looping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.