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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:37+00:00 2026-05-23T16:06:37+00:00

I’ve been searching for a week now on how to accomplish this but none

  • 0

I’ve been searching for a week now on how to accomplish this but none of the tutorials have worked – I typically get a message “resource id 18.”

I’m creating a bank simulation game.

End goal: I want a variable “$player_balance” to be the sum of all account balances owned by that player so that it can be displayed at the bottom of the table under account balances.

Here is my code, thanks for any help or direction that you can provide.

function displayMyAccounts(){
   global $database, $session;
   $q = "SELECT game_account_number,game_account_owner,game_account_name,game_account_balance FROM ".TBL_ACCOUNTS." WHERE game_account_owner='".$session->username."'";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }

   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%\">\n";
   echo "<tr><td><b>Account Number</b></td><td><b>Account Name</b></td><td><b>Balance</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $anumber  = mysql_result($result,$i,"game_account_number");
      $aowner = mysql_result($result,$i,"game_account_owner");
      $aname  = mysql_result($result,$i,"game_account_name");
      $abalance   = mysql_result($result,$i,"game_account_balance");
      setlocale(LC_MONETARY, 'en_US');
      $abalance2 = money_format('%(#10n', $abalance);

      echo "<tr><td>$anumber</td><td>$aname</td><td>$abalance2</td></tr>\n";
   }
       echo "<tr><td></td><td></td><td>$player_balance</td></tr>\n";
   echo "</table><br>\n";
}
displayMyAccounts();

The above code is what appears on each player’s “account page.” I want the sum of their accounts to appear on the last row. Thanks for any help, I’ll continue searching and trying in the meantime.

Here is the output based on the above:

    Account Number  Account Name    Balance
    1000083690  Maverick    $ 50,000.00
    1000083696  WellsFargo  $ 50,000.00
    1000083697  Wachovia    $ 50,000.00
  • 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-23T16:06:38+00:00Added an answer on May 23, 2026 at 4:06 pm

    Don’t use mysql_result(). It’s slow and inefficient, and what you’re doing is better done with mysql_fetch_assoc():

    $player_balance = 0;
    // Also, ditch the for loop. This is the typical convention for retrieving results.
    while ($row = mysql_fetch_assoc($result)) {
    
      $abalance1 = money_format('%(#10n', $row['game_account_balance']);
      echo  "<tr><td>{$row['game_account_number']}</td><td>{$row['game_account_name']}</td><td>$abalance1</td></tr>\n";
    
      // Now add to the balance
      $player_balance = $player_balance + $row['game_account_balance'];
    }
    // And output your balance
    $abalance_sum = money_format('%(#10n', $player_balance);
    echo "<tr><td></td><td></td><td>$abalance_sum</td></tr>\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have been unable to fix a problem with Java Unicode and encoding. The
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.