rndilger Posted December 30, 2008 Share Posted December 30, 2008 The problem I'm having can be best described by looking at what I've current got at: http://www.indianasheep.com/memberlist. You'll notice that for the last entry (i.e., RndPig), there are 4 colored dots to the left of the MapIt button. In order to keep this system flexible, I'd like to have these dots arranged into lines of no more than 3 dots per line. Thus, for the RndPig record, I'd like 2 lines of dots (3 dots on first line, 1 dot on second line). The mysql db behind this listing contains a single row for each member and there are columns specifying to which categories a member belongs. What I'm currently doing is looping through and outputing colored dots that indicate whether a member belongs to a certain category. Here is the code I use to do this: for($i=0; $i<=count($field_names); $i++){ if (strtolower($row[$field_names[$i]]) == 'y'){ echo "<img src='images/map/mapmarker". $i .".gif' border='0' alt='". ucwords(str_replace("_"," ",$mem_type[$i])) ."'> "; } } ...where $field_names is an array that contains the actual column (field) names from the db and $row is an array that contains information as to which categories each member belongs (i.e., either a 'y' or a 'n'). This is where I need a little help. I don't know the best way to "paginate" the colored dots into rows of 3 as described above. Would this entail doing a count of the array elements in $row that equal 'y' and then using lots of if statements? Any help is appreciated. Thanks, Ryan Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 30, 2008 Share Posted December 30, 2008 I'm not sure I'm following exactly what you're asking but if you just need two rows of three you may want another variable inside your loop that you increment and insert a linebreak if it's divisible by three. Quote Link to comment Share on other sites More sharing options...
rndilger Posted December 30, 2008 Author Share Posted December 30, 2008 I'm not sure I'm following exactly what you're asking but if you just need two rows of three you may want another variable inside your loop that you increment and insert a linebreak if it's divisible by three. Perfect, I wasn't in the right frame of mind to come up with that simple solution! Ryan Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 30, 2008 Share Posted December 30, 2008 I'm not sure I'm following exactly what you're asking but if you just need two rows of three you may want another variable inside your loop that you increment and insert a linebreak if it's divisible by three. Perfect, I wasn't in the right frame of mind to come up with that simple solution! Ryan Hehe, I understand perfectly. It can be way to easy to overthink a problem, that's why this place is great. EDIT: As a note, you really don't even need to make a new var, just check $i, something like if($i%3 == 0) { echo "<br />"; } Quote Link to comment 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.