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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:15:00+00:00 2026-06-15T13:15:00+00:00

I’m running through a table with a loop to return all the results into

  • 0

I’m running through a table with a loop to return all the results into a nice looking table. It does so fine up until the subquery needs to execute. The subquery looks at another table and uses the $office value from the starting loop to look up the information, from there it just totals up the integer value and assigns it to $paid.

For some reason both loops stop after it returns the first result and outputs $paid. Is it even possible to accomplish what I’m doing? I tried to wrap my head around this and it seems like I could hardcode the values and set individual variables for each result set, but that seems like a lot of work. I just want to display the $paid integer for each result set it returns from the first loop. Hopefully this all makes sense. I greatly appreciate any advice given.

$mysqli = new mysqli ( $db_hostname, $db_username, $db_password, $db_name );
    $query = "select * from `drawer` where date(`date`) = '$mysql_date' order by `office`"; // select result set for selected date and order by office name
    $result = $mysqli->query($query);
    while ( $row = $result->fetch_assoc () ) {

echo "<tr class=table_border>\n"; //display results
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['office']."</td>\n"; // return office name
$office = $row['office']; // grab the office from the first loop to use it in the second loop
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['manager']."</td>\n"; // return manager name
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['scash']."</td>\n"; // display integer value
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['ecash']."</td>\n"; // display integer value

$newquery = "select * from `offer_det` where `office` = '$office' and date(date) = curdate()"; // subquery to display data from another table and insert for each row when the first loop starts
$resultquery = $mysqli->query($newquery);
while ($row=$resultquery->fetch_assoc()) {
    $paid += $row['paid'];
}
echo "<td class=table_rows nowrap width=10%>&nbsp;".$paid."</td>\n"; // both loops end here
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['add']."</td>\n"; // should return integer value
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['remove']."</td>\n"; // should return integer
echo "<td class=table_rows nowrap width=10%>&nbsp;".$row['total']."</td>\n"; // should return integer
}
  • 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-15T13:15:02+00:00Added an answer on June 15, 2026 at 1:15 pm

    You are overwriting $row into inner while loop

    Change

    while ($row=$resultquery->fetch_assoc()) {
        $paid += $row['paid'];
    }
    

    To

    while ($row1=$resultquery->fetch_assoc()) {
        $paid += $row1['paid'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.