Display Data in Multiple Columns from Database using PHP

isplay Data in Multiple Columns

In some scenario we need to display data in multiple columns in a HTML table where each row from database keeps data for a single column of HTML table. The data can be text, image or mixture of both. This article will guide you display data in multiple columns from database using PHP.

 

Example of this kind of arrangement is product catalog which you can see in picture above. The products are displayed in columns along with image and product name.

We have used a while loop to achieve that. The only thing to keep in mind is to print blank columns to maintain equal number of column in each row after displaying last record from database.  For that we have used for loop after end of while.

The code along with comments will let you assist to understand the code and to display data in multiple columns:

The above result can easily be achieved with div structure or HTML lists also. But to understand the technique, i have used tables. Hope it will help you to display data in multiple columns from database using PHP.

You Might Interested In