Click here to Skip to main content
15,394,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print the only part that I click the button print, I have one page web that have many table that the value take from database phpmyadmin, and then for get the data to display at web I put SQL code into my jsp file, the SQL code I use is :
<%
                           Connection con;
                           PreparedStatement pst;
                           ResultSet rs;

                           Class.forName("com.mysql.cj.jdbc.Driver");
                           con = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendance?zeroDateTimeBehavior=CONVERT_TO_NULL", "root", "");

                           String query = "select * from tbl_totalmonday, tbl_totalsunday, tbl_totalholiday";
                           Statement st = con.createStatement();

                           rs = st.executeQuery("select * from tbl_totalmonday, tbl_totalsunday, tbl_totalholiday where idEmploy = idEmployE AND idEmploy = idEmployP");

                           while (rs.next()) {
                       String id = rs.getString("id");
                       %>


so, whenever user enter new data, it will display new table and have many table in that web page, so at every table have a print button, but the print button doesn't work well when I click the print button at other table. Like when I click button print at second table, it will print the first table, so if anyone know how to print the specified part that have SQL loop but different data, I really hope you can help me. Thank You for your help.

What I have tried:

Below have the button print I insert, but it only can print the same table whenever I click button print at other table with different data...
<div class="divContents" id="DIV_ID">
                           <%
                               Connection con;
                               PreparedStatement pst;
                               ResultSet rs;

                               Class.forName("com.mysql.cj.jdbc.Driver");
                               con = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendance?zeroDateTimeBehavior=CONVERT_TO_NULL", "root", "");

                               String query = "select * from tbl_totalmonday, tbl_totalsunday, tbl_totalholiday";
                               Statement st = con.createStatement();

                               rs = st.executeQuery("select * from tbl_totalmonday, tbl_totalsunday, tbl_totalholiday where idEmploy = idEmployE AND idEmploy = idEmployP");

                               while (rs.next()) {
                           String id = rs.getString("id");
                           %>
                       <!-- Begin Page Content -->
                       <div class="container-fluid">

                           <div class="card shadow mb-4 name1" >
                                   <div class="card-header py-3">
                                       <h6 class="m-0 font-weight-bold text-primary">Table Total All OT plus Meal ALW</h6>
                                   </div>
                                   <div class="card-body">

                                       <div class="table-responsive">
                                           <div class="align" align="right">   <button onclick="printFunction()"  class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm">Print</button>
                                           </div>
                                           <script>

                                               function printFunction() {
                                                   var divContents = document.getElementById("DIV_ID").innerHTML;
                                                   var prnt = window.open();
                                                   prnt.document.write(divContents);
                                                   prnt.document.close();
                                                   prnt.focus();
                                                   prnt.print();
                                               }
                                           </script>
                                           <br>


                                           <table class="table table-bordered " border="1" id="dataTable" width="100%" cellspacing="0">
                                               <tr>
                                                   <td style="color: black; font-weight: bold">Employee Name:</td>  <td ><%=rs.getString("Name1")%></td>
                                                   <td style="color: black; font-weight: bold">Employee Name:</td>  <td ><%=rs.getString("NameE")%></td>
                                                   <td style="color: black; font-weight: bold">Employee Name:</td>  <td ><%=rs.getString("NameP")%></td>
                                               </tr>
                                               <tr>
                                                   <td style="color: black; font-weight: bold">Id Employee:</td>  <td ><%=rs.getString("idEmploy")%></td>
                                                   <td style="color: black; font-weight: bold">Id Employee:</td>  <td ><%=rs.getString("idEmployE")%></td>
                                                   <td style="color: black; font-weight: bold">Id Employee:</td>  <td ><%=rs.getString("idEmployP")%></td>
                                               </tr>
</form>
                                               </tbody>
                                           </table>
                                       </div></div>
                               </div>
                           </div><%
                               }
                           %>
Posted
Updated 12-Jun-22 22:13pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900