开发者

PHP fmod problem

开发者 https://www.devze.com 2022-12-09 18:23 出处:网络
<?php $i = 1; $y = 5; ?> <?php while (have_posts(开发者_运维问答)) : the_post(); ?> <?php
<?php
$i = 1;
$y = 5;
?>
<?php while (have_posts(开发者_运维问答)) : the_post(); ?>
<?php
if (fmod($i, $y) == 0) {
    echo '<tr>';
}
?>

What i'm doing wrong? I want every 5 time to show the <tr>,any help?


I don't see where you increment $i; nor why you are using fmod instead of % (fmod is only for floating-point moduli). Try this code:

<?php
$i = 1;
$y = 5;
while (have_posts())
{
  the_post();
  if ($i % $y == 0) echo '<tr>';
  $i++;
}
?>


Is it just a typo, or did you overlook the missing dollar sign in your y variable? It should be $y.

0

精彩评论

暂无评论...
验证码 换一张
取 消