A
A
Alexander Ruzhevich2015-11-06 18:56:48
PHP
Alexander Ruzhevich, 2015-11-06 18:56:48

How to make a separator for every third record?

Good day. As conceived by the designer, the records are lined up in 3 pieces and between 1 and 2 and also between 2 and 3 there is a separator line, but on the last record in the line (third) it is not. How to put it into practice? I was told that I need a counter that, with a value of "3", would not display a line after recording, or would not display a separator at the end of the line

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ilyusha Prokopiev, 2015-11-06
@ruzhevich

And records are deduced by a cycle? Then you create a variable, for example, i. On each pass of the loop, the variable is increased by one, when the variable is 3, do not draw a line, but assign the value 0 to the variable.

A
AlikDex, 2015-11-06
@AlikDex

I agree with Vladislav Turchinsky. If you still need it in PHP, then an implementation example is below.

<?php
<?php
$yourArray = [
  'one',
  'two',
  'three',
  'four',
  'five',
  'six',
  'seven',
];

$chunkedArr = array_chunk ($yourArray, 2);

foreach ($chunkedArr as $key=>$val) {
  $chunkedArr[$key] = implode (", ", $val);
}

print_r( implode(" | ", $chunkedArr ) );

string(42) "one, two | three, four | five, six | seven"

K
keslo, 2015-11-06
@keslo

- Add a border-right border to the entry class, for example.
- Creating the same class with :nth-child(3n+3) with border: none.

A
Alexander Ruzhevich, 2015-11-07
@ruzhevich

Thanks to everyone who responded, but the records are displayed in a cycle, and the solution was found, maybe it will come in handy for someone
before the cycle is set to
<?php $i = 0; ?>
in the loop we increase by 1
<?php $i++ ?>
and in the place we need (if the variable is equal to 3) we remove the separator and reset the counter
<?php if ( $i == 3) { $i=0;} else { echo 'here is the class that outputs the delimiter'; } ?>
another counter was also created which, when the display is reduced when only 2 records are placed, puts a separator only between the first and second records,
insert in the same places next to the first counter and reset the counter
<?php $ii = 0; ?>
<?php $ii++ ?>
<?php if ( $ii == 2) { $ii=0;} else { echo 'here is the class that outputs the delimiter'; } ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question