Hartley Posted August 29, 2007 Share Posted August 29, 2007 So I have a database, and I want to split the results into 2 columns. I don't want to alternate them, but have the first half in the left column, and the second half in the right column. How can I handle this so that it does it automatically no matter what number of entries (and so that if it's an odd number, the one overflow is on the left). Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/67230-splitting-mysql-results/ Share on other sites More sharing options...
Barand Posted August 29, 2007 Share Posted August 29, 2007 If you are alternating you can process the result set directly but in this situation is easiest to put the results is an array and output from the array. If you have N rows ( where $rows = ceil(count($array)/2) ) for ($r=0; $r < N; $r++) new row output rth item output (r+N)th item close row end for Quote Link to comment https://forums.phpfreaks.com/topic/67230-splitting-mysql-results/#findComment-337226 Share on other sites More sharing options...
Hartley Posted August 30, 2007 Author Share Posted August 30, 2007 Alternating gets confusing with alphabetical order and I'd try to get them in 2 columns, sort of an A-M, N-Z style, though it wouldn't always end up that perfect. Is it possible to achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/67230-splitting-mysql-results/#findComment-337558 Share on other sites More sharing options...
Barand Posted August 30, 2007 Share Posted August 30, 2007 I've just told you how Quote Link to comment https://forums.phpfreaks.com/topic/67230-splitting-mysql-results/#findComment-337680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.