Skip to content
Advertisement

php – Database value display in multiple table cell based on category

JavaScript

Let us assume the variable $quantity_sum_show value as 8.

From the above table, Body,Material,Elastomer row field values are getting from database. I need to display the values based on the category in the table cells. Below is the sql query to fetch hno_count, hno, but confused how to display it in the table based on the category field.

Sql query:

JavaScript

Sql Result:

JavaScript

Example: In the above result table as we can see, there are three rows with 4,1,3 respectively for the Body category. What I’m expecting to display in the table is for the starting 4 rows of Body field, the heat no(hno1) need to display. For fifth row(hno2) need to display and for the next 3 rows(hno3) need to display.

FYI, it’s not mandatory that sum of all hno_count should be the $quantity_sum_show value, but the sum of hno_count will not be greater than the $quantity_sum_show value.

Expected Output:

JavaScript

Advertisement

Answer

From your question your input data looks like this:

JavaScript

So the first thing we need to do is expand that data into a format which we can iterate over…

JavaScript

Next we need to know how many rows of data there are…

JavaScript

Then we can loop through the result set and output the data in the format intended…

JavaScript

Output

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