1

Topic: Understanding ROWCNT

I feel under qualified to talk about this subject, but it is a discussion/tutor that many may or may not need. My logic may not be spot on, but it works.

SCENARIO

To illustrate this problem lets look at the call I have for my videos on my site.

{videos:limit=12,cache_time=0,cache_name="yout"}

Note in the call that I am displaying 12 videos in the call.

Now lets look at the image for the above call

http://www.filipina-lady.net/test253/row.jpg

If you are like me, you look at the above image and wonder what happen. I'm calling 12 images. There are 4 images in the first two rows. Why did it not display three rows of 4 images? 12 divided by 3 = 4 so why is the math off?  As you can see in the third row there is only 3 images and the 4th image goes to the next line.  It has to do with ROWCNT.

THE EXT

Lets look at the ROWCNT used in my extension  for the above call. In this case the extension is ext.videos (note, you may or may not be using this ext. It does not matter for this tutor. It could be the member extension that displays new members. The point of this tutor is  to understand ROWCNT).

My video ext has a ROWCNT  that looks like this:
               
<!-- IF rowlast OR rowcnt mod "11" == "10" -->

In this ROWCNT the numbers 11 == 10  is the key to how your images will display on your site.

ANALYZING VLAD'S COMMENTS

I asked vlad once about ROWCNT and this was his reply:

1. rowcnt is pulled from a "for loop". When something is stored in array (for example search results), you check which row you're on by using that variable.

2. To insert some code after every 4 items, use this code <!-- IF rowcnt mod "4" == "3" --></tr><tr><!-- ENDIF -->

3. It inserts tr/td after specific number of items is reached. For example above code will insert new line after every 4 items

<table>
  <tr>
    <!-- BEGIN variable -->
      <td>member picture</td>
      <!-- IF rowcnt mod "4" == "3" --></tr><tr><!-- ENDIF -->
    <!-- END variable -->
  </tr>
</table>

Well word by word explanation of the above is: if remainder of "rowcnt" value divided by 4 equals to 3, then we insert a new row. "rowcnt" starts with 0 and increases by 1 with each new iteration. You can try this using your windows calculator:
0 mod 4
1 mod 4
2 mod 4
3 mod 4
4 mod 4
5 mod 4
etc You'll see that every 4 times there will be a remainder of 3.

I really appreciated vlad taking the time to provide such thorough feedback. Now I just needed to try to figure it out. I knew I would need  pencil and paper along with my trusty calculator to do so.

First off, if you are like me, you could easily guess what to change your ROWCNT numbers to that may fix the problem. I do that a lot. I use trial and error until I get it right even if I don't understand why it works.

What would you change the 11 == 10 in my extension to get even rows of 4?  Would you use 12 == 10 or 11 == 12? If you guessed 11 == 12 you were right, but do you know why?

PENCIL AND PAPER

The key in vlad's comment was this:  "if remainder of "rowcnt" value divided by 4 equals to 3, then we insert a new row." In my extension I'm dealing with 11 == 10. So I would say: if the remainder of rowcnt value divided by 11 equals 10, then we insert a new row.

Now the boring part.  Lets get our calculator out and do the math.

0 / 11 = 0 (no new row)
1 / 11 = .090 (no new row)
2 / 11 = .18 (no new row)
3 / 11 = .27 (no new row)
4 / 11 = .36 (no new row)
5 / 11 = .45 (no new row)
6 / 11 = .54 (now new row)
7 / 11 = .63 (no new row)
8 / 11 = .72 (no new row)
9 / 11 = .81 (no new row)
10/11 = .90 (no new row)

11/11 = 1 In my above image, this is where the spit happen in the 3rd row. Once it reached 11 images, the next image went to the next row. Do you see why?

Look at this explanation again:

"if the remainder of rowcnt value divided by 11 equals 10, then we insert a new row"  What is the remainder of 11/11=1? Do the math. subtract 1 from 11, what do you get - 10. And what does 10 equal in the formula - a new row.

Ok, for what it is worth, that is my logic for understanding ROWCNT. I probably made it  too complicated so if anyone has an easier or simpler explanation, I'm all ears. But if you do not want to do the math, you can always do what I do, guess smile

2

Re: Understanding ROWCNT

very very good ! thanks

3

Re: Understanding ROWCNT

Ok db3204, this is totally confusing..

I have in my ext.members.tpl code:
<!-- IF rowlast OR rowcnt mod "7" == "7" --><div class="clear"></div><!-- ENDIF -->

1) Now I intend to have 3 lines of 7 members. As I understand it, the first digit represents the number of images in a row. Is this correct? As of today because I haven't filled my new members bar, I won't know if this is right yet.

2) In my header template I have {members:limit=21.... } So I know it will stop at 21 images

3) What does the second digit actually represent in the rowcnt code? In most rowcnt codes I've seen, the second digit usually seems to be 1 digit less than the first. So mine should be "7" == "6" should it? Or is the second digit representing the number of rows? Vlad said yours should be "4" == "3", this would make sense.

Therefore my rowcnt should be "7" == "3", is this right? I am totally confused now.

4

Re: Understanding ROWCNT

1. rowcnt mod "7" == "6"

3. "mod" is a modular (you can learn more about it here). In short, it gives you a remainder after dividing one number by another one. "rowcnt" is just a counter as db3204 described above.

Developer

5

Re: Understanding ROWCNT

Thankyou vlad smile

6

Re: Understanding ROWCNT

Hey Max

Sorry I did not get to reply right away. I have been so busy with my site that I have not been checking vldForum a much as I use to.

You are doing what I did. Logically you would think the numbers equal rows and columns. Indirectly they do, but the numbers are there to do math with more than to be used as an indicator of how many rows and columns.

Even though I can do the math now, I still usually guess a few times to see if I get it right. If my guesses don't give desired results, than I do the math. I'm no math whiz, so usually I have to get out pen and paper to do the numbers. Can't do it in my head like I'm sure some can.

cheers
dan

7

Re: Understanding ROWCNT

Ok db3204,

I studied your post must have been 2 hours and I have found a way to understand half the formula.

1) Determine the total number of images in your block. This is 12.

2) Multiply the two values in your rowcnt code together. The end result should be a number which is evenly divisible by 12, your total number of images. However one integer should comprise the number of images in a row, or the number of total images. In vlad's example, 3 x 4 = 12. In your example, 11 x 12 = 132 which is a number which your total images 12 is evenly divided into.

3) My image array will contain 3 rows of 7 each, totalling 21 images. My rowcnt code is "7" == "6". Well 7 x 6 = 42. Therefore, 42 / 21 = 2. Why "7" == "6"? Well 7 is the total images in a row and multiplied by 6 gives an integer divisible by 21. However vlad didn't clearly explain why then I can't use "7" == "3" which both multiplied together give 21.

It appears that either of the two rowcnt numbers can be the total number of images you want in a row or the total number of images in the block.

Now lets say I wanted a block of not 21 but 28 images. 4 rows of 7 images. Well 7 x 8= 56. So in this case would my rowcnt would be "7" == "8"? Why not "7" == "4"?

And lets say you wanted 7 rows of 9 images which equals 63 images in total. Would your rowcnt be
"9" == "7"? Or could you use "9" == "14"?

Does that make sense? I may not be right but maybe I'm on the right track.

Last edited by maxpower (2009-08-15 12:08:34)

8

Re: Understanding ROWCNT

I think you are on the right track, Max. Maybe vlad will chime in. I'm glad you added your thoughts because this is one subject that many seem to not understand. The more input, the better. Thanks.

9

Re: Understanding ROWCNT

Thanks, all... This thread fixed my 2-day headache. smile

Basic research is what I'm doing when I don't know what I'm doing.