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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:41:49+00:00 2026-06-01T18:41:49+00:00

Figured it out, solution below! I have an HTML table that is being populated

  • 0

Figured it out, solution below!

I have an HTML table that is being populated by data from a database with two tables using the following structure:

Table 1:
------------------------------
|id|data|other_data|more_data|
------------------------------

Table 2:
--------------------------------
|id|entryId|fileType|other_data|
--------------------------------

I’m joining these two tables similarly:

SELECT * FROM table1 LEFT JOIN table2 ON table2.entryId = table1.id

Sample return:

------------------------------------------------------------
|id|data|other_data|more_data|id|entryId|fileType|other_data|
-------------------------------------------------------------
|1 |....|..........|.........|1| 1      |file1   |..........|
|1 |....|..........|.........|2| 1      |file2   |..........|
|2 |....|..........|.........|3| 2      |file1   |..........|
|2 |....|..........|.........|4| 2      |file2   |..........|
|3 |....|..........|.........|5| 3      |file1   |..........|
|4 |....|..........|.........|6| 4      |file2   |..........|

For each case, I am expecting at least one result, usually two which I would like to sort based on the fileType field. fileType can either be file1 or file2.

<table>
<tr>
<td>file1 data here</td>
<td>file 2 data here</td>
</tr>
</table>

If there is no file1 or file 2 in the result, insert a dash (-), but always keep that table structured in the same way, and in the same order. How can I accomplish this? I tried a simple if/else construct, but my logic is wrong and returns the data out of order; I’m having trouble wrapping my head around a working solution.

while(docs.next) {

if(docs.getString("fileType").equals("file1")) {
        .....<td>file 1 data</td>
    }

else if(docs.getString("fileType").equals("file2")){
        .....<td>file 2 data</td>
    }
}

As always, your help is greatly appreciated!

**Figured it out, thanks! Solution:

I broke the logic into two queries then used what you suggest:
– first query grabs data from table1, sets up HTML table
– set two variables(fileData1, fileData2) null
– second query grabs data from table2, loops through the results to find matches and changes the actual value if the result exists
– after loop, print table cells with results**

  • 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-01T18:41:50+00:00Added an answer on June 1, 2026 at 6:41 pm

    If I understand correctly, you need to print both <td>s no matter what. Your if condition restricts printing <td> – it will print <td> only when the given condition is satisfied. So you need to alter it. Instead, you need to do this – read through docs, get fileType. If it is file1, assign value for that to a variable, that was initialized to null. If it is file2 , assign value for that to a variable, that was initialized to null. Then test for that variable and print either “-” or the content on each case.

    Assuming variables file1Data and file2Data denotes string data from file1 and file2 respectively for each iteration over docs,

    while(docs.next) {
       String file1Data = null;
       String file2Data = null;
       if(docs.getString("fileType").equals("file1")) {
       // assign value for fiel1Data here
       } 
       if(docs.getString("fileType").equals("file2")) {
       // assign value for fiel2Data here
       }
       System.out.println("<tr>");
       System.out.println("<td>" + (file1Data == null || file1Data.equals("")?"-" : file1Data) + "</td>");
       System.out.println("<td>" + (file2Data == null || file2Data.equals("")?"-" : file2Data) + "</td>");
       System.out.println("</tr>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird problem that i can't figure out a solution for: I've
Figured it out myself, solution below. I'm trying to save a dynamic number of
I have been trying to figure out a solution but nothing has really presented
The problem itself is simple, but I can't figure out a solution that does
I have a seemingly simple problem, but I can't quite figure out a solution.
I figured out that CUDA does not work in 64bit mode on my mac
I figured out that of course . and SPACE aren't allowed. Are there other
Figured it out, see Update below. I'm trying to work with a particular web
I have actually figured this problem out, but it took me days, so I
I have a table that contain follow logic. The table display list of names

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.