首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PHP中从1开始生成序列号并将其插入到表中?

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

Stack Overflow用户
提问于 2017-07-12 21:10:25
回答 1查看 250关注 0票数 0

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

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

代码语言:javascript
复制
<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“=循环总数

EN

回答 1

Stack Overflow用户

发布于 2017-07-12 21:19:46

您需要使用for循环并打印循环中的表行

代码语言:javascript
复制
<?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 } ?>

然后,您可以在循环中的任意位置打印数字

代码语言:javascript
复制
<?php echo $i ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45058625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档