@Ashwini Agarwal-løsningen er delvis, og for at vise både billedindikatorer og billeder kan det ikke gøres sådan, fordi kan ikke køre while-løkken to gange, så arbejdsløsningen vil være at oprette arrays før loop, indlæse hentede data i arrays og derefter brug foreach
funktion for begge indicators
og for at vise images
håndtere også den active
klasse med counter
PHP-kode
<?php
$id=$_GET['id'];
$qry="select rel_movies from released_movies where rel_id='$id' ";
$qryr=$con->query($qry);
while($rr=$qryr->fetch_assoc()){
$film=$rr['rel_movies'];
$q="select * from gallery where category='$film'";
$qr=$con->query($q);
$rows = array(); //Declare rows as arrays before loop
while($r=$qr->fetch_assoc()){ //Run Loop
$rows[] = $r; //Load Data in arrays
} //close Loop
} //close First Loop, Side Note, You don't need This Loop
?>
Nu vil karrusellen inde i Modal Body se sådan ud (forklaret med kommentarer for at forstå, hvordan dette fungerer)
<div class="modal-body">
<div id="lightbox" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
$i = 1; //Counter
foreach ($rows as $r): //Foreach
$ol_class = ($i == 1) ? 'active' : ''; //Set class active for only indicator which belongs to respective Image
?>
//Here I add the counter to data-slide attribute and add class to indicator
<li data-target="#lightbox" data-slide-to="<?php echo $i;?>" class="<?php echo $ol_class; ?>"></li>
<?php $i++; ?>
<?php endforeach; ?> //Close Foreach
</ol>
<div class="carousel-inner">
<?php
$i = 1; //Counter
foreach ($rows as $r): //Foreach
$item_class = ($i == 1) ? 'item active' : 'item'; //Set class active for image which is showing
?>
<div class="<?php echo $item_class; ?>"> // Define Active Class Here
<img src="../AbaamAdmin/uploads/<?php echo $r['images'];?>" width="900px" height="500px" >
</div>
<?php $i++; ?>
<?php endforeach; ?> // Close Foreach
</div>
<a class="left carousel-control" href="#lightbox" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#lightbox" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>