在表列中显示连续的数字


Display consecutive number in table column

我想在我的表列中显示一个连续的数字。

我正在使用一个wordpress页面模板。下面你可以看到我的示例代码:

<div id="comparison-table" style="display: block;">
<h2 id="matratzen-testsieger">Die besten Federkernmatratzen</h2>
<table class="comparison-table" style="max-width: 1050px;">
   <tbody>
      <tr class="row-name" data-name="name">
         <th> </th>
         <?php int i=0; //Here I am initializing the counter?>
         <?php if ( $posts->have_posts() ) { while ( $posts->have_posts() ) : $posts->the_post(); global $post; ?>
         <td>
            <div class="product-title">
            <div class="ranking">
               <?php i++; echo i; ?>
               <div><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
         </td>
         <?php endwhile; } else { echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>'; } ?>
      </tr>
      <tr class="row-mtester-rating" data-name="mtester-rating">
      <th> </th>
      <?php if ( $posts->have_posts() ) { while ( $posts->have_posts() ) : $posts->the_post(); global $post; ?>
      <td>
      <span class="review-total-boxi"><?php the_field('wp_review_total'); ?> / 5.0</span>
      </td>
      <?php endwhile; } else { echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>'; } ?>
   </tbody>
</table>
</div>

我尝试了一个简单的计数器i,它在while循环中递增,然后在echoed中递增。

作为输出,我什么也得不到。

有什么建议我做错了吗?

感谢您的回复!

我想你混淆了另一种语言。您正在创建和调用变量,而不使用$和在PHP中,您不初始化变量的类型

<?php int i=0; ?>
应该

<?php $i = 0; ?>

<?php i++; echo i; ?>
应该

<?php $i++; echo $i; ?>