动态 div 交替变化 PHP
Dynamic div change alternatively in PHP
我在这里生成动态 div 我想在 PHP 中交替执行 div 作为动态值.. 请帮助我关联这个。
这里$count=$content_faq['number'];结果的计数
<?php
foreach($content_faq['rows'] as $howit){
$count=$content_faq['number'];
$title=$howit->title;
$images=$howit->image;
$description=$howit->description;
for($i=0; $i < $count;$i++)
{
if($i % 2){ //remove quotes around 0
?>
<!-- div first -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
</div>
</section><!-- closing of section is misplaced -->
</div>
<?php } else {?>
<!-- div Second -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
</div>
</section>
</div>
<?php } } } ?>
我的 if and else
条件在那种情况下不起作用有什么问题有任何人可以帮助解决这个问题..
我想要 if id =1 then if part div execute, if id=2 cos its divisible and reminder is 0 then else part to be executed.. 但我没有得到同样的结果我在这里做错了。
出色的模数运算符的工作!
使用 foreach 循环获取数组 ID:
foreach ($content_faq['rows'] as $id=>$howit) {
然后用取模交替
if ($id % 2)
这将交替评估为 0 和 1,我们知道这是假的和真的。
我在这里生成动态 div 我想在 PHP 中交替执行 div 作为动态值.. 请帮助我关联这个。
这里$count=$content_faq['number'];结果的计数
<?php
foreach($content_faq['rows'] as $howit){
$count=$content_faq['number'];
$title=$howit->title;
$images=$howit->image;
$description=$howit->description;
for($i=0; $i < $count;$i++)
{
if($i % 2){ //remove quotes around 0
?>
<!-- div first -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
</div>
</section><!-- closing of section is misplaced -->
</div>
<?php } else {?>
<!-- div Second -->
<div id="<?php echo rtrim($title); ?>" style="height: 400px; margin-top: 40px;">
<section >
<div class="container about-intro" >
<div class="col-lg-6">
<div class="" data-aos="fade-up">
<?php echo $description; ?>
</div>
</div>
<div class="col-lg-6">
<div class="image1_work">
<img class="img" height="380px" width="100%" src="<?=SITE_MEDIA?>images/howitwork/<?php echo $images?>" alt="image" >
</div>
</div>
</div>
</section>
</div>
<?php } } } ?>
我的 if and else
条件在那种情况下不起作用有什么问题有任何人可以帮助解决这个问题..
我想要 if id =1 then if part div execute, if id=2 cos its divisible and reminder is 0 then else part to be executed.. 但我没有得到同样的结果我在这里做错了。
出色的模数运算符的工作!
使用 foreach 循环获取数组 ID:
foreach ($content_faq['rows'] as $id=>$howit) {
然后用取模交替
if ($id % 2)
这将交替评估为 0 和 1,我们知道这是假的和真的。