Displaying Image in Carousel from MySQLi using PHP Variables - php

So I am wanting to create a carousel gallery for my site, so the owners can change the background images when they would like to, and delete images at their will.
Images can already be uploaded, however, displaying them in the carousel is being... difficult.
I am using the MDBootstap Template for the Carousel which looks like this:
<div class="carousel-item active">
<div class="view" style="background-image: url('http://www.fun4all.org/img/vtc.png'); background-repeat: no-repeat; background-size: cover;">
<!-- Mask & flexbox options-->
<div class="mask rgba-black-light d-flex justify-content-center align-items-center">
</div>
<!-- Mask & flexbox options-->
</div>
</div>
although I have attempted to modify the template to be able to show the MySQLi data.
Connection to the Database looks like this: (db.php)
<?php
$conn = mysqli_connect("localhost","highlown_REDACTED","REDACTED");
$db = mysqli_select_db($conn, "highlown_REDACTED");
$query = mysqli_query($conn, "SELECT * FROM images");
$rows = mysqli_num_rows($query);
mysqli_close($conn);
?>
Then how I have attempted to include it within the Gallery
<?php
for ($i=1;$i<$rows;$i++) {
$row = mysqli_fetch_assoc($query);
?>
<div class="carousel-item">
<div class="view" style="background-image: url('http://www.URL.org/gallery/img/upload/<?php echo htmlspecialchars($row['directory']); ?>'); background-repeat: no-repeat; background-size: cover;">
<!-- Mask & flexbox options-->
<div class="mask rgba-black-light d-flex justify-content-center align-items-center">
</div>
<!-- Mask & flexbox options-->
</div>
</div>
<?php
}
?>
I don't really need an explanation on how the stuff works, I just want a correction, please. I will let you know if your answer works or not.
Many Thanks, Ethan B.
PS, if you need more information, let me know.

Related

get_theme_file_uri won't add image

I am trying to figure out why my image won't add to the WordPress website I am creating. This course came with other images that will display but not the ones I add as a jpg file. I am not sure why it will add the other jpg images but not the ones I want. Here's my code:
<?php get_header(); ?>
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg') ?>)"></div>
<div class="page-banner__content container t-center c-white">
<h1 class="headline headline--large">TBS</h1>
<h2 class="headline headline--medium">Working to make traffic safer</h2>
<h3 class="headline headline--small">Explore constructing, utlities, and other types of work we do</h3>
Service & Support
Signs
Utilities
</div>
</div>
I am not sure if I need to add more information to this.
Try this:
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg'); height:200px;width:100% ?>)"></div>
<div class="page-banner__content container t-center c-white">
<h1 class="headline headline--large">TBS</h1>
<h2 class="headline headline--medium">Working to make traffic safer</h2>
<h3 class="headline headline--small">Explore constructing, utlities, and other types of work we do</h3>
Service & Support
Signs
Utilities
</div>
</div>
Problem is that you are closing <div> tag without adding any content in that:
<div class="page-banner__bg-image" style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg') ?>);"></div>
So I have added height and width for showing the background image. Either you can add some content or specify the height and width of that div.
I figured it out. I added the image to my image folder but it wasn't refreshed in VS editor. If you add images to a folder, make sure to refresh the image folder.

display images from database in horizontal way

hi this is my code which display images from mysql database
<?php
error_reporting(0);
include_once 'dbconfig.php';
$id=$_POST['id'];
$q="select * from services ";
$qq=mysql_query($q)
or die(mysql_error());
while($row=mysql_fetch_array($qq)){
$s1=$row[image];
?>
<?php
$p1="admin/services/uploads-services/";
echo '<img src="'.$p1.$s1.'" class="img-responsive" alt="Blog Image">'; ?>
<?php } ?>
it appears in vertical way but i want to make it appear in horizontal way
how can i do this ?
If you want images to be in same row, add display: inline-block to them.
.img-responsive {
display: inline-block;
}
Probably because you visualize the images not in a defined col. If you want to visualize 3 images at a line, you should have
<div class="col-md-12">
<div class="col-md-4">
put your image here
</div>
<div class="col-md-4">
put your image here
</div>
<div class="col-md-4">
put your image here
</div>

How to centre-align 'n' number of images, coming from database

I have links of images stored in database,I want to bring the set of images at the centre of the screen (which in my case is left-aligned). No matter how many pictures comes dynamically, the set of the images should be aligned centre.
Iam using bootstrap for designing and here is how my code look like:
<div class="row">
<div class="col-md-12 text-center">
<?php
foreach($n as $val)
{ // loop to iterate 'n' image links
?>
<div class="col-md-1">
<img src="<?php echo $val; ?>" // images showing up.
</div>
<?php
}
?>
</div>
</div>
I am adding an image below to demonstrate the situation.
I have tried the following:
bootstrap classes : center-block (which is based on margin)
bootstrap classes : text-center (which is based on text-align)
bootstrap classes : "img-responsive center-block"
Please Note:
I don't want to push the content toward centre forcefully (like using of bootstrap class "col-md-push-3" or something as such, because the number of images to be displayed is not fixed. They vary time to time)
The column classes you are using to wrap the images [col-md-1]are floated left by default....you'd have to override that behaviour.
.text-center .col-md-1 {
float: none;
display: inline-block;
}
.text-center .col-md-1 {
float: none;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
You can still use some good old CSS using FlexBox, as shown on this Fiddle. Basically, it uses a structure like:
<div class="container">
<div class="picture">
<img src="http://lorempixel.com/image_output/food-q-c-200-200-1.jpg" />
</div>
</div>
And then, with some FlexBox properties, you can achieve what you want:
.container {
display: flex;
}
.picture {
flex: 1 1;
width: 100%;
}
img {
width: 100%;
}
To sum up, you put the container in flex mode, and then all its div would occupy same space. Some intermediary divs are required in order to keep the aspect ratio of each image.
If you want to center them in case of you have less pictures available, you can still use the justify-content: center; property, setting a maximum width on the divs, such as this other Fiddle.
Note however that this solution would not work on IE9-.
Make a div with text-align:center
Amand then make a div inside it with display:inline-block

Why is my bootstrap code not responsive?

I'm building a custom wordpress theme and I was watching my buddy write up code for a page using bootstrap. He made it so that it is centered on his monitor. I believe he is using a 4:3 monitor. When I look at the page on my 24inch widescreen the page is not centered. What am I doing wrong that is making the page not responsive to any screen size? This is my code for the page:
<?php get_header(); ?>
<div class="row">
<div class="span1"></div>
<div class="span8" id="container">
<?php the_post(); ?>
<?php the_content(); ?>
</div>
<div class="span2">
<?php get_sidebar();?>
</div>
<div class="span1"></div>
</div>
<?php get_footer(); ?>
and here is the code for the header:
<meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>;charset=<?php bloginfo('charset'); ?>" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />
<center>
<div class="row">
<div class="span3"></div>
<div class="span6">
<div class="logo">
<h1 id="logo-mathew">Mathew J. Mari</h1>
<h3 id="logo-attorney">Attorney At Law</h3>
</div>
</div>
<div class="span3"></div>
</div>
</center>
I am new to using bootstrap so maybe I'm using the wrong syntax for it to be responsive or I've left something out? I just want it to be responsive on all monitors, having it centered and utilizing a 1-8-2-1 column layout. Any help would be greatly appreciated.
It does seem like you are using an older version of Bootstrap. The Newer version mnakes it much easier to center your elements.
Your code with the elements being used inside a container class. One of bootstrap's 3 easier method of centering a div.
And with the new bootstrap, the use of class names like col-md-1 , col-md-8 etc will be used. Make sure you read up on Bootstraps' grid system. Makes life much easier for responsive designs
<div class="container">
<div class="row">
<div class="col-md-1"></div>
</div>
<div class="container">
<div class="col-md-8">
<?php the_post(); ?>
<?php the_content(); ?>
</div>
<div class="col-md-2">
<?php get_sidebar();?>
</div>
<div class="col-md-1"></div>
</div>
container tag is missing must be used over the row and all other tags
Use .container for a responsive fixed width container.
...
Use .container-fluid for a full width container, spanning the entire width of your viewport.
...
Firstly you are using the old version of Bootstrap i.e 2.3 and bootstrap has already released the new version 3.0 so please upgrade it.
Now in the version you are using, there is another css that you need to give reference and that is for the responsive. and also add the .container-fluid for your main container.
Add Class .col-centered to your page wrapper div
.col-centered{
margin:0 auto;
float : none;
display:block;
}
it centered your page in any size monitor

How to place Bootstrap Carousel image captions outside the carousel div?

apologies if this has been covered anywhere here. I tried searching, but only found topics related to styling and positioning captions within the carousel code…
So, I have a layout that contains three columns:
The left column contains general information related to each page/project.
The center column contains a Bootstrap 3 carousel with images.
The right column is where I was planning on displaying all the captions related to the images in the center Carousel.
I can't quite figure out how to get the captions working in the right column. To clarify, the captions will change with each carousel slide, just as they do in the default carousel setting. I basically want to move the captions off the image, and into the right column.
I am using Kirby (www.getkirby.com) as my CMS and I am using a foreach loop to get the code for the images, etc. in the carousel. Here is my current code, including the caption section (which I am trying to move…)
<div id="center" class="col-xs-12 col-sm-6 col-md-8">
<?php $imagepage = $page->children()->first() ?>
<?php if($imagepage->hasImages()): ?>
<div id="merry-go-round" class="carousel slide">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php $n=0; foreach($imagepage->images() as $image): $n++; ?>
<div class="item<?php if($n==1) echo ' active' ?>">
<img style="display:block; margin-left: auto; margin-right: auto;" src="<?php echo $image->url() ?>" alt="<?php echo html($image->title()) ?>" class="img-responsive">
<div class="carousel-caption"><?php echo $image->img_title() ?></div>
</div>
<?php endforeach ?>
<?php endif ?>
</div><!-- /carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#merry-go-round" data-slide="prev"></a>
<a class="right carousel-control" href="#merry-go-round" data-slide="next"></a>
</div><!-- /merry-go-round -->
</div><!-- /#center -->
<div id="right" class="col-xs-12 col-sm-3 col-md-2">
<p>THIS IS WHERE I AM TRYING TO PUT THE CAROUSEL CAPTIONS…</p>
</div><!-- /#right -->
I've tried by best but I am all out of ideas. I thought maybe I could do something like make the caption a variable:
<?php $test_caption = $image->img_title() ?><?php echo $test_caption ?>
but this doesn't work outside the carousel area. I'm guessing it's that it won't work outside of the foreach loop?
Anyway, if anyone has any suggestions I would really appreciate it. I'm learning PHP as I go along, but I don't know any javascript so I'm hoping there's a solution outside that. And again, I'm using Bootstrap 3.
Here is a link to a fiddle I made (without all the php stuff…):
http://jsfiddle.net/4tMfJ/2/
Based on Twitter Bootstrap Carousel - access current index
You can add the code below to your javascript (after loading jquery / bootstrap)
$(function() {
$('.carousel').carousel();
var caption = $('div.item:nth-child(1) .carousel-caption');
$('#right h1').html(caption.html());
caption.css('display','none');
$(".carousel").on('slide.bs.carousel', function(evt) {
var caption = $('div.item:nth-child(' + ($(evt.relatedTarget).index()+1) + ') .carousel-caption');
$('#right h1').html(caption.html());
caption.css('display','none');
});
});
also see: http://jsfiddle.net/4tMfJ/3/
Thanks Bass for your answer it worked for me !
But i did not want to have replicated content so i did it my way ;)
$("#slider").on('slide.bs.carousel', function(evt) {
var step = $(evt.relatedTarget).index();
$('#slider_captions .carousel-caption:not(#caption-'+step+')').fadeOut('fast', function() {
$('#caption-'+step).fadeIn();
});
});
http://jsfiddle.net/4fBVV/3/

Categories