Skip to content
Advertisement

can we simplify “while” inside of “while”?

i need some little help ,,,

I have a data like this.., (I use php mysql)

Initially there was no problem with this, but as time goes by, my data is getting bigger and bigger. finally its made my program slow .. I think maybe because I used “while” inside of “while”. make SQL is called multiple times. is there a solution to make it faster ??

non-original data

I have hundreds of data in tb1 and thousands in tb2 T.T

Advertisement

Answer

You should not be using loops to iterate over tables. SQL is an inherently set based declarative language. So, you should just join the tables, order the result set, and then use a single loop with presentation logic. Use this query:

Then, use this PHP script:

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