Solved

MySQL and JSP: combining and saperating queries

Posted on 2003-11-05
5
226 Views
Last Modified: 2010-04-01
i have 2 tables same structure but different data.
i have html table generated dynamically using data from the above tables.

the syntax:
<table width="100%" border="1">
        <tr bgcolor="#3399FF">
          <td colspan="5"><div align="center"><font color="#FFFFFF">
<strong>Out</strong></font></div></td>
        </tr>
        <tr>
          <td width="20%"><div align="center">Date</div></td>
          <td width="15%"><div align="center">TT No</div></td>
          <td width="15%"><div align="center">From</div></td>
          <td width="35%"><div align="center">Desc</div></td>
          <td width="15%"><div align="center">Amount</div></td>
        </tr>
<%
      Statement stmt4  = C.createStatement();
      ResultSet RS4    = stmt4.executeQuery("select *,sum(amount) as total from papertrans where type='out' group by type");
      
      while(RS4.next()){
            pdate2 = RS4.getString("date");
            pttno2 = RS4.getString("ttno");
            pfrom2 = RS4.getString("loc");
            pdescription2 = RS4.getString("description");
            pamount2 = RS4.getFloat("amount");
            float ptotal2 = RS4.getFloat("total");
%>
        <tr>
          <td width="20%"><div align="right"><%=pdate2%></div></td>
          <td width="15%"><div align="right"><%=pttno2%></div></td>
          <td width="15%"><div align="right"><%=pfrom2%></div></td>
          <td width="35%"><div align="right"><%=pdescription2%></div></td>
          <td width="15%"><div align="right"><%=sharePrice.format(pamount2)%></div></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>Total</td>
          <td><div align="right"><%=sharePrice.format(ptotal2)%></div></td>
        </tr>
     </table>

question:
it only managed to show the 1st info but it showed the amount(ptotal2) correctly.
how am i suppose to display the other info without saperating the query into 2?
0
Comment
Question by:yapsing
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
savalou earned 25 total points
ID: 9691710
Don't calculate the total in your query and don't group by type.  So you get all your records out.  Calculate your total in your JSP.

          float ptotal2 = 0;
     ResultSet RS4    = stmt4.executeQuery("select *,sum(amount) as total from papertrans where type='out'");
   
     while(RS4.next()){
...
         ptotal2 += pamount2;

0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 25 total points
ID: 9691939
change is like..
<%
    Statement stmt4  = C.createStatement();
    ResultSet RS4    = stmt4.executeQuery("select * from papertrans where type='out' group by type");
   
     while(RS4.next()){
          pdate2 = RS4.getString("date");
         pttno2 = RS4.getString("ttno");
         pfrom2 = RS4.getString("loc");
         pdescription2 = RS4.getString("description");
         pamount2 = RS4.getFloat("amount");
         float ptotal2 += pamount2;
%>
that should do it









0
 
LVL 3

Expert Comment

by:savalou
ID: 9692321
yeah, I'd say it should be
     ResultSet RS4    = stmt4.executeQuery("select * from papertrans where type='out'");
Still no need to group by.
0
 
LVL 1

Author Comment

by:yapsing
ID: 9692394
another problem:
i only need to show the total once.

 <td width="15%"><div align="right"><%=sharePrice.format(pamount2)%> </div></td>
   </tr>
<%
   }//i can't put this here
%>
    <tr>
    <td>&nbsp;</td>
...
    <td><%=sharePrice.format(ptotal2)%></td>
0
 
LVL 1

Author Comment

by:yapsing
ID: 9692557
okie, i think i got it
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet concurrency 13 110
getting param value 7 57
love6 challenge java 31 133
listing all functions in JavaScript 19 216
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question