JBRTaylor Posted October 8, 2014 Share Posted October 8, 2014 Hi As a beginner after much work i managed to display the results of a call to an access database as a list and have quite happy managed to get them to display as a list in a table. Below is the code i have used to do this. while($row = odbc_fetch_array($UserProdResults)) { echo $row['ProductionName'] . "<br>"; } What i would like to be able to do is to populate each cell of a table which is 3 columns wide with the results eg: Result 1 result 2 Result 3 Result 4 Result 5 Result 6 Result 7 etc.... At the moment i have only been able to populate the one column. Any help / advice very gratefully received. Jon Quote Link to comment https://forums.phpfreaks.com/topic/291508-managing-results-from-odbc_fetch_array/ Share on other sites More sharing options...
Barand Posted October 8, 2014 Share Posted October 8, 2014 The mod operator "%" gives the remainder when a number is divided by another. So if you keep a count of the rows ($rowcount) then start a new table row when $rowcount % 3 == 0 Quote Link to comment https://forums.phpfreaks.com/topic/291508-managing-results-from-odbc_fetch_array/#findComment-1493049 Share on other sites More sharing options...
ginerjm Posted October 8, 2014 Share Posted October 8, 2014 To elaborate on Barand's offering: In your loop you need to build an html table row only once for every 3 times thru the loop. So you conduct the test he gave you and if it equals zero, you output the start row tag (after first checking if you have a row already started) and then output the td tag with that occurrence of data. Then you increment the rowcount var and loop again. This time the test will fail, so you only output the td tag. Play with it and you'll figure out the little things as you do Quote Link to comment https://forums.phpfreaks.com/topic/291508-managing-results-from-odbc_fetch_array/#findComment-1493053 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.