php_guest Posted May 9, 2009 Share Posted May 9, 2009 I would like to display results on table like in the image. The problems are two: First 5 results are displayed in column with different background color, another 5 results with another and another 5 results with another. And each second row of each column has white background. So if I choose while ($row=mysql_fetch_assoc($result2)), how I can pick up every second results to display them with different style and again 5 results, than 5-10 and then 10-15? Does mysql_fetch_assoc give any option to say something like mysql_fetch_assoc...if row is 1-5 {do this} elseif row is 10-15, ...? Thank you Link to comment https://forums.phpfreaks.com/topic/157481-solved-while-fetch_assoc-only-every-second-result/ Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 No. mysql_fetch_assoc does not have any such feature. You have to count rows by yourself. Link to comment https://forums.phpfreaks.com/topic/157481-solved-while-fetch_assoc-only-every-second-result/#findComment-830242 Share on other sites More sharing options...
php_guest Posted May 9, 2009 Author Share Posted May 9, 2009 thank you but how to count by myself? For example if a query is SELECT nickname FROM users WHERE gender=male ORDER BY age. How to count which row is the first, which the second, which 3rd etc.? Thank you Link to comment https://forums.phpfreaks.com/topic/157481-solved-while-fetch_assoc-only-every-second-result/#findComment-830273 Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 You probably use while loop in PHP to lop through the results. Create a variable that will increment on each pass of the loop. $rowCounter = 0; while($row = mysql_fetch_assoc($result)) { $rowCounter++; if(($rowCounter % 2) == 0) { //style for even rows } else { //style for odd rows } } Link to comment https://forums.phpfreaks.com/topic/157481-solved-while-fetch_assoc-only-every-second-result/#findComment-830278 Share on other sites More sharing options...
php_guest Posted May 9, 2009 Author Share Posted May 9, 2009 Thank you, that is what I was looking for! Link to comment https://forums.phpfreaks.com/topic/157481-solved-while-fetch_assoc-only-every-second-result/#findComment-830460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.