I have a MySQL table that contains people’s names.
Using PHP, what’s the best way of dividing these names up and displaying them in 3 columns.
This could be achieved using an HTML table, but would it be possible to do this using only <div>‘s?
I heard that this can be done using the % operator. Would this be the best way, and how would this be done?
You could do this using the modulus operator, however it’s actually possible with just CSS.
Using
display: inline-block, you can get a good column effect. Take a look at this JSFiddle here. I’m only using JavaScript because I’m lazy; the<div>list would be generated by PHP in your case. If you want to confine them to a certain width, just put them in a container<div>with a fixed width.I’ve come up with a solution using tables, which is really what you should be doing (you haven’t given any special use cases). The code is below, as well as a working demo here.
And to finish off, we have our column-centric layout, this time going back to
divs. There’s some CSS here; this should be put in a separate file, not left inline.