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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:57:00+00:00 2026-06-05T14:57:00+00:00

I have this PHP syntax and works as I expected : $sqldata = mysql_query(

  • 0

I have this PHP syntax and works as I expected :

$sqldata = mysql_query("
SELECT FirstName, LastName, NumberOfChildren, SchoolTuition FROM User WHERE User.Username = '$Username' LIMIT 1;
");

$rows = array();
while($r = mysql_fetch_assoc($sqldata)) {
  $rows[] = $r;
}

echo json_encode($rows);

now, the problem is I want to calculate total school tuition (NumberOfChildren * SchoolTuition) and it must be done before json_encode() function. and my client doesn’t want to add one extra column on their database.

so I must calculate this TOTAL School Tuition using PHP and put it back on $rows array as latest value of array before json_encode.

I tried calculate using mysql_fetch_array first to get $rows[2] and $rows[3], but since I already use mysql_fetch_assoc before, this mysql_fetch_array won’t work.

last thing, I mysql_fetch_assoc generates 2 dimensional array. because when I use print_r($rows), I see this :

Array ( [0] => Array ( [FirstName] => Mary [LastName] => Smith [NumberOfChildren] => 3 [SchoolTuition] => 2000 ) ) 

while array_push function only used to push 1 dimensional array, right?

please kindly give me solution of this problem. thank you very much.

  • 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-05T14:57:03+00:00Added an answer on June 5, 2026 at 2:57 pm

    You can just do the calculation in SQL, without having to add the column.

    SELECT FirstName, LastName, NumberOfChildren, SchoolTuition, 
        (NumberOfChildren * SchoolTuiton) AS TotalSchoolTuiton 
    FROM User WHERE User.Username = '$Username' LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I have this PHP script which i'm grabbing images from a directory and displaying
i have this error Parse error: syntax error, unexpected '{' in receive/register.php on line
I have an idea of using this syntax in php. It illustrates that there
I have this PHP code in a loop for every post on the admin
i have this php code and keep on getting errors upon fixing each error.
I have this PHP snippet: <?php $colors = array('red','green','blue'); foreach ($colors as &$item) {
I have this php code $filename = verbs.php; // http://alylores.x10.mx/vega/verbs2.php $handle = fopen($filename, r);
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
So I have this php web app, and one of my folder contains some

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.