如何从1开始在PHP中生成序列号并将它们插入表中?

时间:2017-07-12 13:10:25

标签: php wordpress woocommerce

我想在每个重复的总元素(<th rowspan=""><?php esc_html_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?></th>)之后插入一个序号,从1开始,然后是2,3,4,......

为了更清晰起见,它应该对所有项目进行编号。这是代码,下面是我试图达到的图像。

<tr class="order-total recurring-total">
    <?php if ( $display_th ) : $display_th = false; ?>
        <th rowspan=""><?php esc_html_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?></th>
        <td data-title="<?php esc_attr_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?>"><?php wcs_cart_totals_order_total_html( $recurring_cart ); ?></td>
    <?php else : ?>
        <th rowspan=""><?php esc_html_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?></th>
        <td><?php wcs_cart_totals_order_total_html( $recurring_cart ); ?></td>
    <?php endif; ?>
</tr>

这是我想要完成的图像; “wiederkehrende gesamtsumme”=经常性总计

enter image description here

1 个答案:

答案 0 :(得分:0)

你需要在循环中使用for循环和打印表行

<?php for($i = 1; $i <= $n ; $i++) { ?>
<tr class="order-total recurring-total">
        <?php if ( $display_th ) : $display_th = false; ?>
            <th rowspan=""><?php esc_html_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?></th>
            <td data-title="<?php esc_attr_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?>"><?php wcs_cart_totals_order_total_html( $recurring_cart ); ?></td>
        <?php else : ?>
            <th rowspan=""><?php esc_html_e( 'Recurring Total', 'woocommerce-subscriptions' ); ?></th>
            <td><?php wcs_cart_totals_order_total_html( $recurring_cart ); ?></td>
        <?php endif; ?>
    </tr>
<?php } ?>

然后你可以在循环中打印你想要的数字

<?php echo $i ?>