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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:23:47+00:00 2026-06-07T11:23:47+00:00

When someone selects a service number, then it will pop down and only give

  • 0

When someone selects a service number, then it will pop down and only give the total one records. I want it to give to total from two tables..

<?php

   $qry = mysql_query ("SELECT SUM(fruit) AS total FROM fruitinventory WHERE `fruitcolor` LIKE '%{$_POST['select']}%'");

$row2 = mysql_fetch_assoc($qry);


    echo $row['total'];

?>

<?php

   $qry = mysql_query ("SELECT SUM(fruitsmart) AS total FROM fruitrotten WHERE `fruitcolor` LIKE '%{$_POST['select']}%'");

$row = mysql_fetch_assoc($qry);


    echo $row['total'];

?>

Then

I want the total of both rows to display then too.

<?php 

$total return = $row+$row2 

?>
  • 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-07T11:23:49+00:00Added an answer on June 7, 2026 at 11:23 am

    You can consolidate your two database calls into a single query, and use the columns of the result as your variables to echo out:

    <?php
        $input = mysql_real_escape_string($_POST['select']);
        $sql = "
            SELECT
                (
                    SELECT SUM(fruit) 
                    FROM fruitinventory 
                    WHERE fruitcolor LIKE '%$input%'
                ) AS totalfruit,
                (
                    SELECT SUM(fruitsmart) 
                    FROM fruitrotten 
                    WHERE fruitcolor LIKE '%$input%'
                ) AS totalfruitsmart";
        $qry = mysql_query($sql);
        $row = mysql_fetch_assoc($qry);
    
        echo $row['totalfruit'] . '<br />';
        echo $row['totalfruitsmart'] . '<br />';
        echo $row['totalfruit'] + $row['totalfruitsmart'];
    ?>
    

    Please, at the very minimum, use mysql_real_escape_string() to help prevent against SQL injection attacks which is what your original code was wide open to.

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

Sidebar

Related Questions

I've got a form that I want different fields to appear when someone selects
I have the following (simplified) table: Service: product_name number_of_clients After someone selects and saves
I've a big problem: When someone selects multiple products, for example he selects 3
I have an implementation of a DefaultTableCellRenderer. When someone selects a row in the
Can someone tell me how can I select the Row under the one on
Please i need someone to help convert this query entity(c#) form. select * from
Someone can give me short explanation how to create bitmap runtime using GDI/GDI+ and
I have a PHP script that selects some data from mysql and throw it
I want to make Restful - Web Service using netbean 6.5, glassfish V 2
I would like to select whole body besides one div. Or maybe someone has

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.