dongqiangteng7319
2014-10-10 09:07
浏览 37
已采纳

如何在更改css背景图像时使用$ x使PHP for循环工作?

Here is my new code. I can't get the for loop to work.. It's only working for $x = 1 but does not run through up to 5..

<?php for ($x=1; $x<=5; $x++) { ?>
<div class="active item">
<div class="fill" style="background-image:url('<?php echo onepage_get_option("onepage_sliderimage" . $x); ?>');">
<div class="container">
<h3 class="carousel_headline"><?php echo onepage_get_option('onepage_sliderimage' . $x . '_heading_middle'); ?></h3>
</div>
</div>
</div>
<?php } ?>

</div>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulang6695 2014-10-10 09:09
    已采纳

    Variables in single quotes do not work. Use like this

    This works

    echo "$x"
    

    This does not

    echo '$x'
    

    Use it like this

    "onepage_sliderimage" . $x
    
    'onepage_sliderimage' . $x . '_heading_middle'
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题