kamran hassan
kamran hassan

Reputation: 166

add content on html using PHP

   <div id="slider-edge">
        <div class="left-side-shadow"></div><!-- End .left-side-shadow -->
        <div class="right-side-shadow"></div><!-- End .left-side-shadow -->
        <div id="bxslider" class="container">
            <ul class="bxslider">
                <li>
                   <?php
                    $i =1;
                    $spro = $obj->limitallpro(4);
                    foreach($spro as $sspro){


                    ?>
                    <div class="slider-item">
                      <img src="images/products/big-phone1.jpg" alt="Slider item 3" width="400" height="400">
                        <div class="slider-item-details">
                            <div class="slider-item-wrapper">
                                <h3 class="item-name">
                                    <a href="product.html"><?php echo($sspro['pname']);?></a>
                                </h3>
                                <div class="item-price-container">
                                    <span class="item-price"><?php echo("".$sspro['pprice']." ");?>RS</span>
                                </div><!-- End .item-price-container -->
                                <p><?php echo($sspro['pdetails']);?></p>

                            <a href="cart.php/pid=<?php echo($sspro['pid']);?>" class="item-add-btn">
                                Add to Cart
                            </a>
                            </div><!-- End .slider-item-wrapper -->

                        </div><!-- End .slider-item-details -->
                    </div><!-- End .slider-item -->
                   <?php

                    ?>  



                      <?php
                    if($i%2 == 0){
                    ?>  
                     </li><li>



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

            </ul>
        </div><!-- End #bxslider -->
        </div><!-- #slider-edge -->

I have slider which work as two div per li since i am trying to get conttent from server side what can i do then after every 2 rows of data from server it creates another li and then repeat 2 rows and close it and let it work as long as rows be keep added through server side. i used if case with modulus but that is not working

Upvotes: 0

Views: 67

Answers (3)

Just_Do_It
Just_Do_It

Reputation: 821

In your code try replacing your following code:

<?php
if($i%2 == 0){
?>  
</li><li>



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

with this:

<?php
if($i%2 == 0){
    echo "</li><li>";
}
$i++;
}
?>
</li>

Upvotes: 1

lukasl1991
lukasl1991

Reputation: 251

I am not really sure what your problem is but if I understand correctly, that you everytimes have an open <li>-Tag after your content is rendered?!

You have to check if your loop is in the last iteration and in this case only echo an </li>.

Try

for ($i = 0; $i < count($spro); $i++) {
.........
if($i == count($spro)-1) { echo("</li>"); }
else { echo("</li><li>"); }
}

Upvotes: 1

Prashant
Prashant

Reputation: 100

<div id="slider-edge">
    <div class="left-side-shadow"></div><!-- End .left-side-shadow -->
    <div class="right-side-shadow"></div><!-- End .left-side-shadow -->
    <div id="bxslider" class="container">
        <ul class="bxslider">
            <li>
               <?php
                $i =1;
                $spro = $obj->limitallpro(4);
                foreach($spro as $sspro){


                ?>
                <div class="slider-item">
                  <img src="images/products/big-phone1.jpg" alt="Slider item 3" width="400" height="400">
                    <div class="slider-item-details">
                        <div class="slider-item-wrapper">
                            <h3 class="item-name">
                                <a href="product.html"><?php echo($sspro['pname']);?></a>
                            </h3>
                            <div class="item-price-container">
                                <span class="item-price"><?php echo("".$sspro['pprice']." ");?>RS</span>
                            </div><!-- End .item-price-container -->
                            <p><?php echo($sspro['pdetails']);?></p>

                        <a href="cart.php/pid=<?php echo($sspro['pid']);?>" class="item-add-btn">
                            Add to Cart
                        </a>
                        </div><!-- End .slider-item-wrapper -->

                    </div><!-- End .slider-item-details -->
                </div><!-- End .slider-item -->
               <?php

                ?>  

               </li>

                  <?php
                if($i%2 == 0){
                ?>  
                 <li>



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

        </ul>
    </div><!-- End #bxslider -->
    </div><!-- #slider-edge -->

here close the php inside the same li where you have open the php and where is the second li being close hope this helps

Upvotes: 1

Related Questions