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

  • Home
  • SEARCH
  • 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 8783039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:43:35+00:00 2026-06-13T20:43:35+00:00

The table_calc structure (minimized) is: | id | value_1 | value_2 | the number

  • 0

The table_calc structure (minimized) is:

| id | value_1 | value_2 |

the number of rows is between 70 and 250 or more.

I want to update the fields in “table_calc” with values resulting from other calculations ($value_update_1 and 2, …), values applied different to the fields in the table.

Before I used a table on the web page and from there I updated the table.
Now I want to update the values directly without having to take them in the page, as it should work.

I started to write the code below:

$stmt_update = $conn_bd->prepare('select * from table_calc');
$stmt_update->execute(array());
$result_stmt_update = $stmt_update->fetchAll();
foreach($result_stmt_update as $rrows_update) {
  $cal_id = $rrows_update[id];
  $cal_value_1 = $rrows_update['value_1'];
  $cal_value_2 = $rrows_update['value_2'];
}

$value_update_1 = 100.25;
$value_update_2 = 150.25;

$count_id = count($cal_id);
$stmt = $conn_bd->prepare('UPDATE table_calc SET value_1 = :value_1, value_2 = :value_2 WHERE id = :id');
$i = 0;
while($i < $count_id) {
  $stmt->bindParam(':value_1', '.$cal_value_1[$i].' * '.$value_update_2.');
  $stmt->bindParam(':value_2', '.$cal_value_2[$i].' * '.$value_update_1.');
  $stmt->bindParam(':id', $cal_id[$i]);
  $stmt->execute();
  $i++;
}

but it doesn’t work

Can you help?

  • 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-13T20:43:37+00:00Added an answer on June 13, 2026 at 8:43 pm

    I can spot a few issues on your code:

    • On line 8:

      $cal_id = $rrows_update[id];
                              ^^
      

      You need quotes there.

    • On line 20, you call your variable as if it were an array, but you don’t set it as such on lines 9-10.
    • Again on line 20, you should bind the final value to the parameter, not leave it to be evaluated by MySQL.

    So the corrected version would be:

    $stmt_update = $conn_bd->prepare('select * from table_calc');
    $stmt_update->execute(array());
    $result_stmt_update = $stmt_update->fetchAll();
    foreach ($result_stmt_update as $rrows_update) {
        //Added array push operators. To make them arrays.
        $cal_id[]      = $rrows_update["id"];
        $cal_value_1[] = $rrows_update['value_1'];
        $cal_value_2[] = $rrows_update['value_2'];
    }
    
    $value_update_1 = 100.25;
    $value_update_2 = 150.25;
    
    $count_id = count($cal_id);
    $stmt     = $conn_bd->prepare('UPDATE table_calc SET value_1 = :value_1, value_2 = :value_2 WHERE id = :id');
    $i        = 0;
    while ($i < $count_id) {
        //Altered the binding so that you bind the final value.
        //Also changed to bindValue.
        $stmt->bindValue(':value_1', $cal_value_1[$i] * $value_update_2);
        $stmt->bindValue(':value_2', $cal_value_2[$i] * $value_update_1);
        $stmt->bindValue(':id', $cal_id[$i]);
        $stmt->execute();
        $i++;
    }
    

    Also, when making batch changes to the database, you may want to use Transactions, to make sure all changes are registered as expected.

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

Sidebar

Related Questions

The autofilter is sorting data vertically, but I want to filter rows horizontally. Lets
I know how to use SQL_CALC_FOUND_ROWS with Limit to return total number of rows
i am working on following link: http://www.marvelfloors.com/ProductDetails.asp?ProductCode=0_OH501 i want to compare the values in
I'm trying to get the total of calc.transport Table 3_product_folder contains duplicate values (column
Table structure id (p) | date | id2 (fk) | id3 (fk) where (p)
Table A has two columns: ID and name I want to input 3 ID
Table is created, but rows are empty, why? MySqlConnection conn = new MySqlConnection(...); conn.Open();
I have a mysql table jobs . This is the basic structure of jobs
I've run the following query: UPDATE main_table, reference_table SET main_table.calc_column = (CASE WHEN main_table.incr
I have a table and want to calculate each element like: calc-this-cost * calc-this-cost(value

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.