i want to display this slideshow dynamically  please help me. 
        I am getting more than
        3 images if i put dynamic code

        <div class="row">
        <div id="carousel-reviews" class="carousel slide" data-ride="carousel">

        <div class="carousel-inner">
        <div class="item active">
            <!-------------------------------->
            <div class="col-md-4 col-sm-6">
            <div class="block-text rel zmin">
            <a title="" href="#">Active1</a>

            </div>
            </div>

            <!-------------------------------->
            <div class="col-md-4 col-sm-6 hidden-xs">
            <div class="block-text rel zmin">
            <a title="" href="#">Avtive2</a>

            </div>
            </div>
            <!-------------------------------->
            <div class="col-md-4 col-sm-6 hidden-sm hidden-xs">
            <div class="block-text rel zmin">
            <a title="" href="#">Avtive3</a>

            </div>
            </div>
            <!-------------------------------->

        </div><!------------------------------//item1------------------------------->   

        </div> <!---carousel-reviews ---->


        <a class="left carousel-control" href="#carousel-reviews" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
        </a>
        <a class="right carousel-control" href="#carousel-reviews" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
        </a>
   </div>

Dani AI

Generated

Short diagnosis: your static markup shows one carousel slide that contains three columns, but the dynamic loop in your later post emits one slide per database row and applies the slide class to every iteration. That both multiplies slides and leaves every slide marked active, so the carousel behaves incorrectly. was right to ask for a minimal example to reproduce the issue; ’s suggestion to limit the result is an option only if you truly want exactly three entries total.

Recommended approach (keeps the original 3-per-slide layout): iterate the result set with a counter and a “first” flag. Start a new slide container when the counter is divisible by three, mark that first container as active once, output one column per row inside the current slide, and close the slide after three columns. After the loop, close any unclosed slide. Use a modern DB API (mysqli or PDO) instead of the deprecated mysql_* functions, and wrap output with an escaping function to prevent XSS.

Example implementation pattern (adjust connection and field names as needed):

// assume $mysqli is a mysqli connection
$perSlide = 3;
$counter = 0;
$first = true;

$result = $mysqli->query("SELECT alumini_name FROM alumini");
echo '<div class="carousel-inner">';
while ($row = $result->fetch_assoc()) {
    if ($counter % $perSlide === 0) {
        echo '<div class="item' . ($first ? ' active' : '') . '"><div class="row">';
        $first = false;
    }
    echo '<div class="col-md-4">', htmlspecialchars($row['alumini_name']), '</div>';
    $counter++;
    if ($counter % $perSlide === 0) {
        echo '</div></div>';
    }
}
if ($counter % $perSlide !== 0) echo '</div></div>';
echo '</div>';

Notes: generate carousel indicators from the number of slides if you need dots; if you only want three records total then restricting the query is simpler. If this still misbehaves, paste a minimal runnable snippet (only the HTML + loop) as suggested so the exact markup can be checked.

Recommended Answers

All 3 Replies

This is only the HTML code. Can you upload a working do on jsfiddle.net to see what is actually happening? Or provide ONLY the relevant code here?

<?php
include('db.php');
$sel = mysql_query("select * from alumini");
?>
        <div class="row">
            <div id="carousel-reviews" class="carousel slide" data-ride="carousel">
              <div class="carousel-inner">


  <?php

  while($row = mysql_fetch_array($sel)){
  ?>
                    <div class="item active">
                     <!-------------------------------->
                        <div class="col-md-4 col-sm-6">
                            <div class="block-text rel zmin">
                               <?php
                                echo $row['alumini_name'];

                                ?>

                            </div>
                        </div>


                </div><!------------------------------//item1------------------------------->   
    <?php

    }
    ?>


                </div> <!---carousel-reviews ---->

                <a class="left carousel-control" href="#carousel-reviews" role="button" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left"></span>
                </a>
                <a class="right carousel-control" href="#carousel-reviews" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                </a>
            </div>

Maybe because there are more than 3 images in your database?

Try $sel = mysql_query("SELECT * FROM alumini LIMIT 3");

The LIMIT statment will only select 3 images.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.