Reputation: 269
I am trying to get values from database table with use of foreach , as i am getting result but it is showing all value from table as i am using it for slide show how can i get 1 detail at single time... This is my code
<div class="col-md-10">
<div class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php
$result_array = $this->db->get('vm_feedback')->result_array();
foreach ($result_array as $key => $v) {?>
<div class="item active">
<div class="col-md-12">
<div class="testimonial-text">
<p style="color:black;"><?php echo $v['feed_desc'];?></p>
<span class="testimonial-by"><?php echo $v['feed_name'];?></span>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
Upvotes: 1
Views: 118
Reputation: 85
<?php $i = 1;
foreach ($result_array as $key => $v ) {?>
<div class="testimonial-item <?php if($i == 1) echo "active"; ?>">
<span> <img src="<?php echo base_url().'backend_assets/media/feedimg/'.$v['feed_img'];?>" class="testimonial-img img-responsive img-circle" alt="image"></span>
<div class="testimonial-text">
<p ><?php echo $v['feed_desc'];?></p>
<span class="testimonial-by"><div class="text-center"><?php echo $v['feed_name'].'<br>'.$v['feed_des'];?></div></span>
</div>
</div> <?php $i++; } ?>
Upvotes: 1
Reputation: 24
You have to put a condition on as currently all the items div are active so it is not looking as you want. So use another variable to add active at once.
<div class="col-md-10">
<div class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php
$result_array = $this->db->get('vm_feedback')->result_array();
$i = 1;
foreach ($result_array as $key => $v) {?>
<div class="item <?php if($i == 1) echo "active"; ?>">
<div class="col-md-12">
<div class="testimonial-text">
<p style="color:black;"><?php echo $v['feed_desc'];?></p>
<span class="testimonial-by"><?php echo $v['feed_name'];?></span>
</div>
</div>
</div>
<?php $i++; } ?>
</div>
</div>
</div>
This will give you the exact result what you want.
Thanks
Upvotes: 0
Reputation: 809
If you want only one record you can go with row_array();
<?php
$v = $this->db->get('vm_feedback')->row_array();
<div class="item active">
<div class="col-md-12">
<div class="testimonial-text">
<p style="color:black;"><?php echo $v['feed_desc'];?></p>
<span class="testimonial-by"><?php echo $v['feed_name'];?></span>
</div>
</div>
</div>
Upvotes: 0