I have $product_image='img1.png,img2.png,img3.png' as a string where I explode $product_image and show image as $pro_img[0], $pro_img[1] and $pro_img[2].
I get error
Message: Undefined offset: 2
if $pro_img[2] doesn't find any image.
I want to solve it using foreach loop but I don't have any idea how can I use foreach to fix this problem?
<?php $pro_img = explode(",",$product_image); ?>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="pro-large text-center">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[0]; ?>" style="width: 50%;height: 35%;" alt="">
</div>
</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<div class="pro-large text-center">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[1]; ?>" style="width: 50%;height: 35%;" alt="">
</div>
</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
<div class="pro-large text-center">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[2]; ?>" style="width: 50%;height: 35%;" alt="">
</div>
</div>
</div>
<ul class="nav product-img-tab" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[0]; ?>" style="width: 50%;height: 96px;" alt="">
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[1]; ?>" style="width: 50%;height: 96px;" alt="">
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[2]; ?>" style="width: 50%;height: 96px;" alt="">
</a>
</li>
</ul>
Since you have various sections (home/profile/contact), that I assume you always want to display either with or without an image, I suggest using isset instead.
Isset simply checks if a key exists in the $pro_img array, and you can use that to decide whether or not to print the image tag:
<?php
$pro_img = explode(",",$product_image);
?>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="pro-large text-center">
<?php if (isset($pro_img[0])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[0]; ?>" style="width: 50%;height: 35%;" alt="">
<?php endif; ?>
</div>
</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<div class="pro-large text-center">
<?php if (isset($pro_img[1])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[1]; ?>" style="width: 50%;height: 35%;" alt="">
<?php endif; ?>
</div>
</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
<div class="pro-large text-center">
<?php if (isset($pro_img[2])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[2]; ?>" style="width: 50%;height: 35%;" alt="">
<?php endif; ?>
</div>
</div>
</div>
<ul class="nav product-img-tab" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">
<?php if (isset($pro_img[0])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[0]; ?>" style="width: 50%;height: 96px;" alt="">
<?php endif; ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">
<?php if (isset($pro_img[1])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[1]; ?>" style="width: 50%;height: 96px;" alt="">
<?php endif; ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">
<?php if (isset($pro_img[2])) : ?>
<img src="<?php echo base_url(); ?>resource/product/<?php echo $pro_img[2]; ?>" style="width: 50%;height: 96px;" alt="">
<?php endif; ?>
</a>
</li>
</ul>
Related
Given this HTML code, how can I create a dynamic Carosuel with thumbnails using Bootstrap 4 that can be updated in back-end using ACF Repeater?
My Repeater field is called carousel_repeater and inside I have an Image field called carosuel_image
HTML code
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="custCarousel" class="carousel slide" data-ride="carousel" align="center">
<!-- slides -->
<div class="carousel-inner">
<div class="carousel-item active"> <img src="https://i.imgur.com/weXVL8M.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/Rpxx6wU.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/83fandJ.jpg" alt="Hills"> </div>
<div class="carousel-item"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" alt="Hills"> </div>
</div> <!-- Left right --> <a class="carousel-control-prev" href="#custCarousel" data-slide="prev"> <span class="carousel-control-prev-icon"></span> </a> <a class="carousel-control-next" href="#custCarousel" data-slide="next"> <span class="carousel-control-next-icon"></span> </a> <!-- Thumbnails -->
<ol class="carousel-indicators list-inline">
<li class="list-inline-item active"> <a id="carousel-selector-0" class="selected" data-slide-to="0" data-target="#custCarousel"> <img src="https://i.imgur.com/weXVL8M.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-1" data-slide-to="1" data-target="#custCarousel"> <img src="https://i.imgur.com/Rpxx6wU.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="2" data-target="#custCarousel"> <img src="https://i.imgur.com/83fandJ.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="3" data-target="#custCarousel"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" class="img-fluid"> </a> </li>
</ol>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="custCarousel" class="carousel slide" data-ride="carousel" align="center">
<div class="carousel-inner">
<?php
if( have_rows('carousel_repeater') ):
// Loop through rows.
while( have_rows('carousel_repeater') ) : the_row();
$sub_value = get_sub_field('sub_field');// whatever ur image field is called
?>
<div class="carousel-item active"> <img src="<?php echo $sub_value['url'] ?>g" alt="Hills"> </div>
<?php
// End loop.
endwhile;
?>
<ol class="carousel-indicators list-inline">
<li class="list-inline-item active"> <a id="carousel-selector-0" class="selected" data-slide-to="0" data-target="#custCarousel"> <img src="https://i.imgur.com/weXVL8M.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-1" data-slide-to="1" data-target="#custCarousel"> <img src="https://i.imgur.com/Rpxx6wU.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="2" data-target="#custCarousel"> <img src="https://i.imgur.com/83fandJ.jpg" class="img-fluid"> </a> </li>
<li class="list-inline-item"> <a id="carousel-selector-2" data-slide-to="3" data-target="#custCarousel"> <img src="https://i.imgur.com/JiQ9Ppv.jpg" class="img-fluid"> </a> </li>
</ol>
</div>
</div>
</div>
</div>
<?php
endif;
?>
Probs something like this, your gna need to play with it as i havent tested it but this is a start, would recommend you look into the documentation for ACF repeaters
https://www.advancedcustomfields.com/resources/repeater/
looking for a steer in the right direction getting this loop working. I'm nearly there but not 100% as I've got a mysterious box appearing at the top and the bottom of the search results. Would anyone be able to check over to see if the loop is right, please?
I've tried jigging the loop around but can't make any sense of it.
<?php get_header(); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<p class="text-muted text-size-small">
<?php
global $wp_query;
echo 'You have '.$wp_query->found_posts.' results found.';?>
</p>
<hr>
<?
php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="media-body">
<h6 class="media-heading text-semibold">
<?php echo get_post_meta(get_the_id(), 'title', true ); ?>,
<?php echo get_post_meta(get_the_id(), 'firstname', true ); ?>,
<?php echo get_post_meta(get_the_id(), 'lastname', true ); ?>
</h6>
<ul class="list-inline list-inline-separate text-muted mb-10">
<li><a href="#" class="text-muted">
<?php echo get_post_meta( get_the_id(), 'type', true ); ?>
</a> </li>
<li><?php echo get_post_meta(get_the_id(), 'netbios_name', true ); ?> |
<?php echo get_post_meta(get_the_id(), 'device_class', true ); ?></li>
</ul>
<?php echo get_post_meta( get_the_id(), 'asset_id', true ); ?>
<?php echo get_post_meta(get_the_id(), 'asset_status', true ); ?>
</div>
<div class="media-right text-nowrap">
<a href="<?php the_permalink();?>"
class="btn btn-warning">View</a>
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-media-on-mobile">
<div class="media-left">
<a href="#">
<img src="assets/images/demo/brands/dell.png" class="img-rounded img-lg" alt="">
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_template_part('footer', 'simple');?>
<?php get_footer(); ?>
Here's what the HTML view is spitting out
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<p class="text-muted text-size-small">
You have 3 results found. </p>
<hr>
<div class="media-body">
<h6 class="media-heading text-
semibold">
, , </h6>
<ul class="list-inline list-inline-
separate text-muted mb-10">
<li><a href="#" class="text-
muted"> </a></li>
<li> | </li>
</ul>
</div>
<div class="media-right text-nowrap">
View
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-
media-on-mobile">
<div class="media-left">
<a href="#">
<img src=" class="img-rounded
img-lg" alt="">
</a>
</div>
<div class="media-body">
<h6 class="media-heading text-
semibold">
34
, , </h6>
<ul class="list-inline list-inline-
separate text-muted mb-10">
<li><a href="#" class="text-
muted"> </a></li>
<li> | </li>
</ul>
</div>
<div class="media-right text-nowrap">
<a href="" class="btn btn-
warning">View</a>
</div>
</li>
<ul class="media-list content-group">
<li class="media panel panel-body stack-
media-on-mobile">
<div class="media-left">
<a href="#">
<img src=" class="img-rounded
img-lg" alt="">
</a>
</div>
<div class="media-body">
<h6 class="media-heading text-
semibold">
34
Mr, User, User </h6>
<ul class="list-inline list-inline-separate text-muted mb-10">
<li>User </li>
<li> | </li>
</ul>
</div>
<div
class="media-right text-nowrap">
View
</div>
</li>
<ul class="media-list content-group">
<li class="media
panel panel-body stack-media-on-mobile">
<div
class="media-left">
<a
href="#">
<img src=" class="img-rounded img-lg" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /main content -->
</div>
<!-- /page content -->
/div>
<!-- /page container -->
I have 24 records in database table. I want to display 6 records in each particular list. So, i need 4 list of records basically.
I have tried this way, refer below code snippet for more details.
<?php
$homeBrands1 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.HOME_LOGO,b.STATUS,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=1");
$homeResult1 =mysql_fetch_array($homeBrands1);
$homeBrands3 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=3");
$homeResult3 =mysql_fetch_array($homeBrands3);
$homeBrands2 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=2");
$homeResult2 =mysql_fetch_array($homeBrands2);
$homeBrands4 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=4");
$homeResult4 =mysql_fetch_array($homeBrands4);
$homeBrands5 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=5");
$homeResult5 =mysql_fetch_array($homeBrands5);
$homeBrands6 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=6");
$homeResult6 =mysql_fetch_array($homeBrands6);
?>
<div class="brands">
<div class="main-heading">
<h3>Our<br> Brands</h3>
</div>
<ul id="slider1" style="overflow:hidden;">
<li style="margin-left: -19px !important; margin-right:22px !important;">
<div class="row" style="padding-left:10px !important; margin-left:1px;">
<div class="col-sm-4">
<div class="brand-cat wow fadeInUp" data-wow-delay="0s">
<img src="images/brands/<?php echo $homeResult1['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult1['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult1['HOME_LOGO'];?>" class="img-responsive" alt=""></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult1['HOME_LOGO'];?>" class="img-responsive" alt=""><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
<div class="brand-cat wow fadeInUp" data-wow-delay="0.4s">
<img src="images/brands/<?php echo $homeResult3['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult3['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult3['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
<div class="col-sm-8">
<div class="row">
<div class="col-sm-6">
<div class="brand-cat stradivarius wow fadeInUp" data-wow-delay="0.3s">
<img src="images/brands/<?php echo $homeResult2['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult2['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult2['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
<div class="brand-cat wow fadeInUp" data-wow-delay="0.5s">
<img src="images/brands/<?php echo $homeResult4['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult4['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult4['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
<div class="col-sm-6" style="padding-left:10px;">
<div class="brand-cat gerry wow fadeInUp" data-wow-delay="0.2s">
<img src="images/brands/<?php echo $homeResult5['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult5['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult5['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
</div>
<div class="row" style="padding:0px !important;">
<div class="col-sm-12">
<div class="brand-cat wow fadeInUp" data-wow-delay="0.5s">
<img src="images/brands/<?php echo $homeResult6['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult6['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult6['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
</div>
<div style="clear:both"></div>
</li>
<li style="margin-left: -19px !important; margin-right:22px !important;">
<div class="row" style="padding-left:10px !important; margin-left:1px;">
<div class="col-sm-4">
<div class="brand-cat wow fadeInUp" data-wow-delay="0s">
<img src="images/brands/<?php echo $homeResult1['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult1['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult1['HOME_LOGO'];?>" class="img-responsive" alt=""></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult1['HOME_LOGO'];?>" class="img-responsive" alt=""><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
<div class="brand-cat wow fadeInUp" data-wow-delay="0.4s">
<img src="images/brands/<?php echo $homeResult3['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult3['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult3['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult3['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
<div class="col-sm-8">
<div class="row">
<div class="col-sm-6">
<div class="brand-cat stradivarius wow fadeInUp" data-wow-delay="0.3s">
<img src="images/brands/<?php echo $homeResult2['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult2['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult2['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult2['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
<div class="brand-cat wow fadeInUp" data-wow-delay="0.5s">
<img src="images/brands/<?php echo $homeResult4['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult4['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult4['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult4['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
<div class="col-sm-6" style="padding-left:10px;">
<div class="brand-cat gerry wow fadeInUp" data-wow-delay="0.2s">
<img src="images/brands/<?php echo $homeResult5['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult5['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult5['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult5['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
</div>
<div class="row" style="padding:0px !important;">
<div class="col-sm-12">
<div class="brand-cat wow fadeInUp" data-wow-delay="0.5s">
<img src="images/brands/<?php echo $homeResult6['IMAGES']; ?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $homeResult6['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>"></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $homeResult6['HOME_LOGO'];?>" class="img-responsive" alt="<?php echo $homeResult6['TITLE'];?>"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
</div>
<div style="clear:both"></div>
</li>
</ul>
</div>
Can anyone help me on this issue?
You only need to do one query, and save your results in an array:
$homeBrands =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.HOME_LOGO,b.STATUS,m.ID,m.TITLE,m.LOGO FROM cms as b
INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' ORDER BY b.POSITION LIMIT 6");
$homeResult =mysql_fetch_array($homeBrands);
Then iterate over the results using a loop (it is the loop that you are missing in your case):
<?php
foreach($homeResult as $hr)
{
?>
<div class="brand-cat wow fadeInUp" data-wow-delay="0s">
<img src="images/brands/<?php echo $hr['IMAGES']; ?>" class="img-responsive" alt="<?php echo $hr['TITLE'];?>">
<div class="brand-name"><img src="images/home_logos/<?php echo $hr['HOME_LOGO'];?>" class="img-responsive" alt=""></div>
<div class="overlay">
<div class="overly-brand-name"><img src="images/home_logos/<?php echo $hr['HOME_LOGO'];?>" class="img-responsive" alt=""><i class="fa fa-long-arrow-right" aria-hidden="true"></i></div>
View more
</div>
</div>
<?php
}
?>
And that's all the code you need, regardless of number of results you want to display. Hope you get the idea. The code is not tested
The below html just shows the images one by one down the page and not in a slideshow. I've put the images in the database giving each one their own column. Is this wrong? How can I make the images be a slideshow. Thanks for helping.
<div id="lodgeGallery" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#lodgeGalleryl" data-slide-to="0" class="active"></li>
<li data-target="#lodgeGalleryl" data-slide-to="1"></li>
<li data-target="#lodgeGalleryl" data-slide-to="2"></li>
<li data-target="#lodgeGalleryl" data-slide-to="3"></li>
<li data-target="#lodgeGalleryl" data-slide-to="4"></li>
<li data-target="#lodgeGalleryl" data-slide-to="5"></li>
<li data-target="#lodgeGalleryl" data-slide-to="6"></li>
<li data-target="#lodgeGalleryl" data-slide-to="7"></li>
<li data-target="#lodgeGalleryl" data-slide-to="8"></li>
<li data-target="#lodgeGalleryl" data-slide-to="9"></li>
<li data-target="#lodgeGalleryl" data-slide-to="10"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<?php
//<img src="img/img1.jpg" alt="">
echo "<img src='img/$galleryImg1'";
?>
</div>
<div class="item">
<?php
//<img src="img/img2.JPG" alt="">
echo "<img src='img/$galleryImg2'";
?>
</div>
<div class="item">
<?php
//<img src="img/img3.png" alt="">
echo "<img src='img/$galleryImg3'";
?>
</div>
<div class="item">
<?php
//<img src="img/img4.png" alt="">
echo "<img src='img/$galleryImg4'";
?>
</div>
<div class="item">
<?php
//<img src="img/img5.jpg" alt="">
echo "<img src='img/$galleryImg5' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img6.jpg" alt="">
echo "<img src='img/$galleryImg6' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img7.jpg" alt="">
echo "<img src='img/$galleryImg7' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img8.jpg" alt="">
echo "<img src='img/$galleryImg8'";
?>
</div>
<div class="item">
<?php
//<img src="img/img9.jpg" alt="">
echo "<img src='img/$galleryImg9' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img10.JPG" alt="">
echo "<img src='img/$galleryImg10' ";
?>
</div>
<div class="item">
<?php
//<img src="img/img11.jpg" alt="">
echo "<img src='img/$galleryImg11' ";
?>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#lodgeGallery" role="button" data- slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#lodgeGallery" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
Seeing your code, i think you have ne error in the syntax of how you echo the image from server.
It should be
"<img src ='img/'.$galleryImg1.'"
For pulling the images from a database:
2 columns: RowID & ImageURL
select RowID, Image URL from db
$sql = ("SELECT RowID,ImageURL FROM db.dbo.table");
$res = odbc_exec($dbConn,$sql);
while ($images = odbc_fetch_array($res)){
echo "<img src="img/".$images."'/>";
}
I have a "Latest Staff Members" panel where it should display my recently added users. All I have is a static display of these users:
<div class="box box-danger <?= !User::isBizAdmin() ? 'hidden' : '' ?>">
<div class="box-header with-border">
<h3 class="box-title">Latest Staff Members</h3>
<div class="box-tools pull-right">
<span class="label label-danger">8 New Members</span>
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div><!-- /.box-header -->
<div class="box-body no-padding">
<ul class="users-list clearfix">
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/frank_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Alexander Pierce</a>
<span class="users-list-date">Today</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Ben_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Norman</a>
<span class="users-list-date">Yesterday</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/iri_girl_face-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Jane</a>
<span class="users-list-date">12 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Jay_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">John</a>
<span class="users-list-date">12 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/Fred_man-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Alexander</a>
<span class="users-list-date">13 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/michela_face_young-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Sarah</a>
<span class="users-list-date">14 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/carla_girl-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Nora</a>
<span class="users-list-date">15 Jan</span>
</li>
<li>
<img src="https://cdn2.iconfinder.com/data/icons/avatar-2/512/hena_woman_face-128.png" alt="User Image"/>
<a class="users-list-name" href="#">Nadia</a>
<span class="users-list-date">15 Jan</span>
</li>
</ul><!-- /.users-list -->
</div><!-- /.box-body -->
<div class="box-footer text-center">
View All Users
</div><!-- /.box-footer -->
</div>
Something like that. Now, in the user table in my database, I added a date_added column and I manually put dates in row.
Do I loop the data? Or use a widget? I don't know how else I should implement this.
EDIT
My controller:
public function actionIndex()
{
if(Yii::$app->user->isGuest){
return $this->render('../site/index');
}
else{
$latestStaffMembers = User::find()->orderBy(['date_added' => SORT_DESC])->limit(8);
return $this->render('dashboard', [
'latestStaffMembers' => $latestStaffMembers,
]);
}
}
In my view:
<?php foreach ($latestStaffMembers as $user) { ?>
<li>
<img src="<?php echo $user->avatar; ?>" alt="User Image"/>
<?= $user->username ?>
<span ><?= $user->date_added ?></span>
</li>
<?php } ?>
Then I get this error:
Trying to get property of non-object
I tried var-dumping $user and it says null.
I'm not sure if this is what you want. I hope it helps somehow.
In your controller action:
$latestStaffMembers = User::find()->orderBy(['date_added' => SORT_DESC])->limit(8)->all();
return $this->render('some-view-file', [
'latestStaffMembers' => $latestStaffMembers,
]);
In your view:
<?php foreach ($latestStaffMembers as $user) { ?>
<li>
<img src="<?= $user->imagePath ?>" alt="User Image"/>
<a class="users-list-name" href="#"><?= $user->name ?></a>
<span class="users-list-date"><?= Yii::$app->formatter->asDate($user->dateAdded, 'd m'); ?></span>
</li>
<?php } ?>
Btw: I saw !User::isBizAdmin() in your code. Is it yours? I would not just hide the list if it is important that only admins may see that. Just don't print it if user is not admin.