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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:03:44+00:00 2026-06-13T04:03:44+00:00

I Have two tables Table1 is idno marks 1 12 1 13 1 22

  • 0

I Have two tables

Table1 is

    idno         marks
     1             12
     1             13
     1             22 
     2             32 
     2             35
     2             11  and so on

Table2 is

    idno          marks
     1              16
     1              22 
     1              21 
     2              35 
     2              16
     2              22   and so on

I am providing a form for user to enter the idno and submit

If user enters “1” in form and submit then the output should be

        Total Marks
            106 

i.e the sum of all marks of Idno 1 in Table1 + sum of all marks of Idno 1 in table2

(12+13+22)+(16+22+21) = 106

and i am using the following code

<form id="form" action="sum.php" method="post">
<td><p align="center"> IDNO : <input type="text" name="id" id="id" maxlength="10"></p></td>
<input type="submit" id="submit" class='btnExample' value="Click here to get your Result"
</form>

<?PHP
$user_name = "admin";
$password = "123456";
$database = "demo";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
$id = mysql_real_escape_string($_POST['id']);
$add = "SELECT htno, SUM(tech) 
FROM(SELECT htno, SUM(tm) AS tech FROM jbit WHERE htno='$id'
UNION ALL  
SELECT htno, SUM(tm1) AS tech  FROM hmm WHERE htno='$id') AS tech4 "; 
$result3 = mysql_query($add);
echo "
<center><table id='mytable' cellspacing='0'  border=3 align=center>
<tr>
<TH scope='col'>Total Marks</TH>
</tr><center>";
while ($row1 = mysql_fetch_assoc($result3)){
echo "<tr>";
echo "<td align=center>" . $row1['tech4']. "</td>";
echo "</tr>";
}
mysql_close($db_handle);
else {
print "Database NOT Found ";
mysql_close($db_handle);
}

but output is blank

please help me out

  • 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-13T04:03:45+00:00Added an answer on June 13, 2026 at 4:03 am

    You seem to be missing GROUP by htno in both parts of the union after WHERE clauses. Or you may consider removing htno field from SELECT clauses of the union.

     select sum(sm) from
       (select Sum(marks) sm from sums1 where idno=1
       union
       select Sum(marks) sm from sums2 where idno=1 ) ss
    

    Tested this on mysql and it works

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

Sidebar

Related Questions

I have two tables: User , table1 and table2 . User has_many table1 .
I have two tables - table1 and table2 table1 has 14 columns and table2
I have two tables table1 and table2 each having a column named email along
I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many
I have two tables: This is table1: product_id|product_desc|product_name|product_s_desc This is table2: product_price_id|product_id|product_price Now I
I have two tables in my database table1, table2. I have a join query
I have two tables TABLE1 and TABLE2 with identical structures. I need a trigger
I have two tables table1 and table2, i need to write a select query
I have two seperate tables: Table1 - id, news, date_added Table2 - id, news,

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.