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 7506707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:20:09+00:00 2026-05-29T22:20:09+00:00

please why is the loop statement breaking, after the multiplication it only update the

  • 0

please why is the loop statement breaking, after the multiplication it only update the last row, tried using a foreach loop for the $totalprice in the update statement it says invalid argument.

if(array_key_exists('item', $_POST)){


// $items = $_POST['item'];
  //foreach($_POST['item'] as $item){
    //echo $item['Pquantity'] . ", ";
    //echo $item['Pidno'] . ", ";
   // }
    //Loop through $_POST items, updating the database for each item
    foreach ($_POST['item'] as $item) { 
        $Pquantity = intval($item['Pquantity']);
        $Pidno = ($item['Pidno']); 
        //echo $Pquantity . ", ";
        //echo $Pidno . ", ";
        //$totalprice = intval($item['Pquantity']) 
        $queryreg = mysql_query("
            UPDATE repplac
                 SET Pquantity = {$Pquantity}
                 WHERE
                       Pidno = '{$Pidno}'
                 AND
                       Uname = '{$_SESSION['username']}'
        ") or die(mysql_error());  

    }
    }
    $pplresult = mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
  while ($row = mysql_fetch_assoc($pplresult)) 
  {
  $totalprice = $row['Price'] * $row['Pquantity'];
  //echo "$totalprice";
  //die();
   $queryreg = mysql_query("
  UPDATE repplac
  SET Tprice = {$totalprice}
  WHERE
                       Pidno = '{$Pidno}'
                 AND
                       Uname = '{$_SESSION['username']}'
    ") or die(mysql_error());  
  }
  • 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-05-29T22:20:11+00:00Added an answer on May 29, 2026 at 10:20 pm

    Inside your foreach you update $Pidno with the following code

    $Pidno = ($item['Pidno']);
    

    Thus you are updating different records in the database. But inside your while loop $Pidno is staying the same the entire time. Thus you are updating the same record over and over. To fix this add the following code at the beginning of the while loop

    while ($row = mysql_fetch_assoc($pplresult)) 
    {
        //get the correct Pidno for this row
        $Pidno = ($row['Pidno']); 
        $totalprice = $row['Price'] * $row['Pquantity'];
    
        // ... the rest of your while loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please explain to me why the very last echo statement is blank? I expect
Please provide tips for effectively using git with svn. What are your best practices?
can anybody help me here please? I am using AJAX for pagination in my
Here is the loop I have so far foreach (CheckBox chk in gpbSchedule.Controls.OfType<CheckBox>()) {
This program will calculate the average grade for 4 exams using a for loop
Possible Duplicate: LINQ equivalent of foreach for IEnumerable<T> please help me to figure out
I'm using NSRunLoop in my application. Just one statement [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; performed
I'm trying to restrict content to posts only from one category. In my loop.php
I'm new in using MVC and I have a question about summarizing the row
I've already implemented this, but as I'm not familiar with the FOR loop statement

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.