Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:43+00:00 2026-06-08T00:34:43+00:00

I am attempting to update a db table based on changes made in a

  • 0

I am attempting to update a db table based on changes made in a tablesorter table. I am sending the information through JS and each item is posted to the php page that will handle the update. This works fine. I now need to have it send an email that shows the buyer name, and the new date processed so that we can calculate commissions from it. When I added my foreach loop, I get 45 separate emails, not just one.
Do I need to add another foreach loop or is there something else that I need to do?
Here is the code for the php page:

    <?php
require_once ('../db.php');
$conn = db_connect();
session_start();


$buyer = $_POST['buyer'];
$isbn = $_POST['isbn'];
$sku = $_POST['sku'];
$cost = $_POST['cost'];
$csmt = $_POST['csmt'];
$hold = $_POST['hold'];
$today = date("Y-m-d");
$n=1;

foreach($sku as $value){ 
// update inventory table
$conn->query("update inventory set cost = $cost, csmt = $csmt, hold = $hold, date_process = $today where sku = $sku");


$holdList[$n] = array('buyer' => $buyer,
            'process date' => $today,
                );
$n++;
}
//loop trough hold list and store in csv format
$csvLists = to_csv($holdList);


function to_csv( $array ) {
 $csv = "";

 if (count($array) == 0) return "No Information found";

 ## Grab the first element to build the header
 $arr = array_pop( $array );
 $temp = array();
 foreach( $arr as $key => $data ) {
   $temp[] = $key;
 }
 $csv = implode( ',', $temp ) . "\r\n";

 ## Add the data from the first element
 $csv .= to_csv_line( $arr );

 ## Add the data for the rest
 foreach( $array as $arr ) {
   $csv .= to_csv_line( $arr );
 }

 return $csv;
}

function to_csv_line( $array ) {
 $temp = array();
 foreach( $array as $elt ) {
   $temp[] = '"' . addslashes( $elt ) . '"';
 }

 $string = implode( ',', $temp ) . "\r\n";

 return $string;
}

$conn->close();

$pricingReport = "The Latest Hold List has been completed. \n";
$pricingReport .= $csvLists;

//send email when pricing specs are done
$to = "jimd@bookcellaronline.com";

$subject = "Hold List";
$body = $pricingReport;
mail($to, $subject, $body);

?>

UPDATE: Here is the JS:

    // to save the changes to the hold table
$("#holdSave").live('click', function() {
$('#holdTable tbody tr').each(function()
        {
$.ajax({
    type: "POST",
    url: "holdSave.php",
    dataType: "json",
    data: ({buyer: $(this).find('#tableBuyer').html(), sku: $(this).find('#tableSku').html(), isbn: $(this).find('#tableISBN').html(),
           cost: $(this).find('#tableCost').val(), csmt: $(this).find('#tableConsignment').val(),
           hold: $(this).find('#tableHold').val()}),
    success: function(data) {

        } // end of success function

}); // end of ajax call
                    }); // end of holdtable tbody function
}); // end of holdSave event
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:34:44+00:00Added an answer on June 8, 2026 at 12:34 am

    The ajax function is being called individually for each record due to which you are getting a mail for each record.

    What you can do is make an JSON object with the entire dataset and then invoke the ajax call:

    var arr={};
    var cnt=0;
    $('#holdTable tbody tr').each(function()
    {
        arr[cnt]={buyer: $(this).find('#tableBuyer').html(), sku: $(this).find('#tableSku').html(), isbn: $(this).find('#tableISBN').html(),
           cost: $(this).find('#tableCost').val(), csmt: $(this).find('#tableConsignment').val(),
           hold: $(this).find('#tableHold').val()};
        cnt++;
    }
    

    Then, pass this object in the ajax call:

        $.ajax({
        type: "POST",
        url: "holdSave.php",
        dataType: "json",
        data: {data:arr},
        success: function(data) {
    
        } // end of success function
        });
    

    On php side, you can parse the $_POST[‘data’] for each record.

    $data=$_POST['data'];
    

    The individual elements of $data are the records you have to insert.
    They can be parsed in a simple for loop as $data[$i]['buyer'],$data[$i]['sku'] …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to update a boolean column in one table based upon the
I am attempting to update an entry in Azure Table Storage. The function is:
i am attempting to update approximately 150,000 records in a table in SQL 2005
I'm attempting to update my database table with the following code: public void onUpgrade(SQLiteDatabase
I'm attempting to update a table using a join statement, but it isn't exactly
I'm trying to update a table based upon the user id from another table.
I have been attempting to reorder a table in a database based on category
I am attempting to update my date_process field using php. The mysql field is
Currently I am attempting to add a new row to a database table through
I am attempting to update a temp table from a source table: UPDATE #DETAIL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.