Jump to content

[SOLVED] "paginating" issue


rndilger

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.  ;D

 

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 />"; }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.