Skip to content
Advertisement

How can I print this data in a HTML table with this format?

Imagine that you have this SQL query result:

JavaScript

And you want to print a table taking into account the ID_KEY, like this:

JavaScript

How can I do that? I want to print a new row when ID_KEY changes. For example, now I have this code:

JavaScript

This code won’t work because “value1”, “value2” and “value3”, are fields that do not exist in my table.

If instead I say this:

JavaScript

This won’t work either, as the value of “VALUE” will be repeated 3 times.

Is it possible to do this or should I restructure the database to store the information in another way?

Advertisement

Answer

The code below would do the trick, but it is dependent on the content of your database and the query. Make sure there are always 3 values per ID_KEY and that the results are sorted properly. The idea is that you repeat to output cells with a value, until the ID_KEY changes. Many minor variations are possible, but in the end they all work on this principle.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement