Setting width and height in image - php

I'm currently coding a slide that uses images that are stored in a database.
I would like to know how can i set width and height for the image. Here's my code:
<div id="my-slide">
<?php
$resultado = mysqli_query($con, "SELECT * FROM slides ORDER BY id DESC LIMIT 3");
while($fila = mysqli_fetch_array($resultado))
{
?>
<div data-lazy-background="images/<?php echo $fila["slideimg"]; ?>">
<h5><?php echo $fila["cap"]; ?></h5>
</div>
<?php
}
?>
</div>

Set Height and Width between your image Div like
<div width="100px" height="100px" data-lazy-background="images/<?php echo $fila["slideimg"]; ?>">

Related

How i can display blob elements is same row with php?

I want to display images in same row,but i can display only under each other. I tried in css display: inline-block; but dont working. Any idea what i need to do? Thanks
The code for display images:
require_once 'dbConfig.php';
$result = $db->query("SELECT image FROM images ORDER BY uploaded DESC");
?>
<?php if($result->num_rows > 0){ ?>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3" >
<a class="lightbox">
<?php while($row = $result->fetch_assoc()){
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'" width="250", " height="250">';}?>
<?php }else{ ?>
<p class="status error">Image(s) not found...</p>
<?php } ?>
</a>
</div>
</div>
It's because you large col is only 3.
Inspect element result
if you are using these images for lightbox thumbnail I would suggest d-flex rather than column system....
Try this code it will work .. now it will loop your columns as well
require_once 'dbConfig.php';
$result = $db->query("SELECT image FROM images ORDER BY uploaded DESC");
?>
<?php if($result->num_rows > 0){ ?>
<div class="row">
<?php while($row = $result->fetch_assoc()){
<div class="col-sm-6 col-md-4 col-lg-3" >
<a class="lightbox">
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'" width="250", " height="250">';}?>
</a>
</div>
<?php }else{ ?>
<p class="status error">Image(s) not found...</p>
<?php } ?>
</div>

HTML Image gallery with Dynamic with PHP

I am trying to display images on a page using the bootstrap grid system, where their names are dynamically created by taking it from a database. For example I have this database, and I want to use the imageID in the src name of each image. Is there any cleaner way to do it without having to manually add a new div etc for each image?
PHP Code for getting image id:
<?php
//dynamically render images
include "../storescripts/connect-mysql.php";
$sql = mysql_query("SELECT * FROM imageGallery ORDER BY dateAdded ASC");
$images = array();
$imageCount = mysql_num_rows($sql); //Count the amount of products
if($imageCount > 0){
while($row = mysql_fetch_array($sql)){
$image = $row['imageID'];
$images[] = $image;
}
}else{
$image_gallery = "<h2>You have no images in the database</h2>";
}
?>
My HTML for displaying the images:
<div class="col-md-12">
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $images[0] ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $images[1] ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $images[2] ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $images[3] ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
</div>
See the image source for how I used the PHP.
As you have images available within $images array. So make a foreach loop inside html div.
<div class="col-md-12">
<?php foreach ($images as $image): ?>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $image; ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<?php endforeach; ?>
</div>
Update
This is for if you want only four divs inside a parent div over and over again.
<?php
$i = 0;
foreach ($images as $image):
if ($i % 4 == 0) {
echo '<div class="col-md-12">';
}
echo '<div class="col-md-3 galleryImg">';
echo '<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/' . $image .'" alt="Jedi Cycle Sport Gallery Image">';
echo '</div><!-- outputs child div -->';
$i++;
if ($i % 4 == 0) {
echo '</div> <!-- outputs parent div -->';
}
endforeach;
if ($i % 4 != 0) {
echo '</div> <!-- outputs parent div-->';
}
Simply use the foreach. Use the code as follows
<div class="col-md-12">
<?php foreach($images as $image) {?>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $image ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<?php } ?>
</div>
Instead of manually adding divs, you can simply use a foreach loop like this:
<div class="col-md-12">
<?php
foreach($images as $image){
?>
<div class="col-md-3 galleryImg">
<img onclick="myfunction(this)" class="galleryImage" src="../img/gallery/<?php echo $image; ?>.png" alt="Jedi Cycle Sport Gallery Image">
</div>
<?php
}
?>
</div>

Use HTML id value in PHP array

I have an array that displays images. I want to make each image clickable to display that specific image larger on an overlaying div.
Each image is displayed and has a different id which is being generated with this code:
<?php if (count($images) > 0) : ?>
<?php $i = 0; ?>
<?php foreach($images as $image) : ?>
<div class=" item" onclick="showOverlay()" id="<?= $i; ?>"><img class="photo" src="<?= $image; ?>"></div>
<?php $i++; ?>
<?php endforeach; ?>
The image in the overlaying div must now use the id value to determine which array item (image) to display.
This is my code that does not work.
<div class="overlay">
<?php
$dirname = "img/photos/$student/$entry/*.JPG";
$images = glob($dirname);
?>
<img src="<?= $images[$_POST['id']]; ?>">

How to make gallery photos even in PHP

Here is my code for a gallery on the website that I am making
<h3>Gallery</h3>
<?php
include"includes/connection.php";
$sql = "select * from kategorije";
$res = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($res))
{
?>
<h4 class="text-center"><?php echo ucwords($row['naziv']); ?></h4>
<?php
$id = $row['sifra'];
$sql1 = "select * from rad where kategorija = $id";
$res1 = mysqli_query($con, $sql1);
$n = mysqli_num_rows($res1);
if($n>0)
{
while($row1 = mysqli_fetch_assoc($res1))
{
$pid = $row1['sifra'];
?>
<div class="col-md-2 col_1">
<img src="uploads/<?php echo $row1['datoteka']; ?>" class="img-responsive" alt=""/>
</div>
<?php
}
}else{
?>
<div class="col-md-2 col_1">
<h6>No Images</h6>
</div>
<?php
}
?>
<div class="clearfix"></div>
<?php
}
?>
I need to make that all the photos in gallery have same height and width when they are uploaded, but I don't know how. I tried to insert this code, but it just doesn't work:
echo"<img src='$dir_path$files[$i]'style='width:150px;height:200px;'>
Also I tried in CSS but it won't work either.
Since you just want to display them in another size, you can achieve this by the way you tried, but with the correct syntax. I hope its this line of code where you want the resized image:
<img src="uploads/<?php echo `$row1['datoteka']; ?>" class="img-responsive" height="200" width="150" alt=""/>`
Let me know it it worked for you. It this wasen't the line you want to do it, keep in mind you simply have to follow the syntax:
<img src="http://url.com/pic.png" width="150" height="200">
Thats all. :)

Using a link to connect two pages in database

I have a page with a search bar that gets images of people in alphabetical order from a database. I also have a page with Next and Previous buttons that allows the user to browse through the database of images using Next and Previous buttons. I'm trying figure out a way to make an image a link so that the user can search through images, click the image, and it takes them to the same image on the Next and Previous page.
This is my code that allows me to search and returns, lastname, firstname, and a picture:
<div class="clearfix"></div>
<?php
if (isset($_GET['LastName'])) {
$ln = $_GET['LastName'];
}
include 'connection.php';
$query = "SELECT * FROM residents WHERE LastName like '$ln%' ";
$result = mysql_query($query);
while($person = mysql_fetch_array($result)) { ?>
<div class="media col-sm-4">
<a class="pull-left" href="Browse.php">
<img class="media-object" src="upload/<?php echo $person['Picture'];?>" width="100"
height="100"/>
</a>
<div class="media-body">
<h4 class="media-heading"><?php echo $person['LastName'] . ", " .
$person['FirstName']; ?></h4>
</div>
The page I'm trying to connect to is "Browse.php" but as you browse through the images the URL changes by increasing..."Browse.php?page=1"..."Browse.php?page=2" and so on. Is there an easy way to connect an image with the corresponding Browse.php page? I've tried several things and any help would be much appreciated!
If you have id column in residents table. You can do something like this.
<div class="clearfix"></div>
<?php
if (isset($_GET['page'])) {
$page_id = $_GET['page'];
}
include 'connection.php';
$query = "SELECT * FROM residents WHERE ID = $page_id";
$result = mysql_query($query);
while($person = mysql_fetch_array($result)) { ?>
<div class="media col-sm-4">
<a class="pull-left" href="Browse.php?page=<?php echo $page_id; ?>">
<img class="media-object" src="upload/<?php echo $person['Picture'];?>" width="100" height="100"/>
</a>
<div class="media-body">
<h4 class="media-heading"><?php echo $person['LastName'] . ", " . $person['FirstName']; ?></h4>
</div>
</div>
<?php } ?>

Categories