How to Display image that coming from PHP file with id? - php

I have Image path like http://sits.in/imageDemo/image.php?image=R171-1.jpg in data base.
I can not load image in php by simply putting image link http://site.in/imageDemo/image.php?image=R171-1.jpg as src.
My code look like this
<?php
$count = 1;
while ($row = mysqli_fetch_array($result)) {
?>
<br>
<br>
<div class="card " style="width: 800px; margin-bottom: 25px;">
<div class="card-body">
<!-- <h5 class="card-title"><b>Product Number : <?php echo $count; ?> </b></h5> -->
<p>Order Id : <?php echo $row['orders_id']; ?></p>
<p>Product Name : <?php echo $row['product_name']; ?></p>
<img src="<?php echo $row['image1']; ?>" class="card-img-bottom" alt="Product Image"
style="width: 100px; height:100px">
</div>
<?php } ?>

I think you need to store path like that in your database
http://sits.in/imageDemo/R171-1.jpg
Also, create folder imageDemo in your local and store image as R171-1.jpg

If you want to use php file as image you need to make that php file to be shown as image file. Use GD libary. More info about how to use it for jpg here: https://www.php.net/manual/en/function.imagecreatefromjpeg.php

Related

rendering images in rows

trying to make this code render images in rows all to no avail. I initially tried to use boostrap's row and column classes and it didn't work. Then I tried the table element still no result. could you spot the problrm?
// Get images from the database
$query = $db->query("SELECT * FROM images ORDER BY id DESC LIMIT 5");
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$imageURL = 'uploads/'.$row["file_name"];
?>
<!-- begin post -->
<div class="container recent-posts">
<table>
<tr>
<td class="card" style="width: 18rem;">
<img src="<?php echo $imageURL; ?>" alt="" />
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</td>
<?php }
}
else{ ?>
<p>No image(s) found...</p>
<?php } ?>
</tr>
</table>
</div>
I've swapped in your db code for an array and foreach, but it is in the same spirit.
Use indentation, to help you get your loops and tags in order.
<?php
$images = [
['file_name' => 'foo.jpg'],
['file_name' => 'bar.jpg'],
['file_name' => 'baz.jpg'],
]
?>
<html>
<?php if(!empty($images)) { ?>
<table>
<tr>
<?php foreach($images as $row) { $imageURL = 'uploads/'.$row["file_name"]; ?>
<td class="card" style="width: 18rem;">
<img src="<?php echo $imageURL; ?>" alt="" />
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</td>
<?php } ?>
</tr>
</table>
<?php } else { ?>
<p>No image(s) found...</p>
<?php } ?>
</html>
As others have said, there isn't anything really to be gained here by using a table.
Does it show you the rest of the html elements or does it show you the message that there is no picture?
Check with the inspect tool what location the src attribute of the img element is.
You can add a backslash in the $imageURL variable
$imageURL = '/uploads/' . $row["file_name"];
Show us the structure and a record of the images table.
Give us more details about what happens when the page is loaded. Like what it loading in your page.
I suggest you ditch the tables and use boostrap instead.
Example here: https://getbootstrap.com/docs/4.0/components/card/

Displaying Image from database?

I have a form that submits, Both text and of course, my image file to my database along with moving to image to a permanent directory.
The issue I am having is when I pull and display the content from the database everything shows apart from the image file.
Images for better context
Database entry, End result
HTML Form
<?php
include("inc/dbconfig.php");
error_reporting(0);
if (isset($_POST['btn-signup'])){
//Text Data Input
$cardName = $_POST['cardName'];
$cardSet = $_POST['cardSet'];
$cardRarity = $_POST['cardRarity'];
$cardImg = $_FILES['cardImage']["name"];
move_uploaded_file($_FILES["cardImage"]["tmp_name"],"../".$_FILES["cardImage"]["name"]);
$cardImgPath = "media/images/userUpload/".$_FILES["cardImage"]["name"];
$mysqlQ =("INSERT INTO cards (cardName, cardSet, cardRarity, cardImage) VALUES ('$cardName', '$cardSet', '$cardRarity', '$cardImgPath')");
mysqli_query($conn,$mysqlQ);
header('Location: directory.php');
}
exit();
?>
Displaying the data
<?php function itemCard (array $row) { ?>
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php echo '../'. $row['cardImage']?>" alt="Card fsa cap">
<div class="card-body">
<h5 class="card-title"><?= $row["cardName"]?></h5>
<p class="card-text">Card Set: <b><?= $row["cardSet"]?></b></p>
<p class="card-text">Card Rarity: <b><?= $row["cardRarity"]?></p>
</div>
</div>
<?php } ?>
can you confirm me your uploaded image stored in folder else follow the steps
use $_SERVER['DOCUMENT_ROOT'] path instead of '../'.
that image moved folder have write permission (777)?

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>

Image doesnt show up in php

In this little snippet of code ,i show how i take the "foto1" column of my database and transfer the value of it to a variable in c# named $foto.
The $foto contains the path of the image corresponding to the product that is showing up. Ive tried to copy and paste the path and ditch out the php part and it works. But when i put it in img src it gives me like the broken image thing.And i cant figure out why it does that.
All help is aprecciated .
Have a nice day :)
<div class="row shop_box-top">
<?php
$ligaBD=odbc_connect('basededadospap','','');
$sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
$resultado=odbc_exec($ligaBD,$sql);
?>
<div class="row shop_box-top">
<?php
while (odbc_fetch_row($resultado))
{
$nome = odbc_result($resultado,2);
$preco= odbc_result($resultado,4);
$foto = odbc_result($resultado,9);
?>
<div class="col-md-3 shop_box"><a href="stansmithflatwhite.html">
<img src="<?php echo $foto; ?>" class="img-responsive" alt=""/>
<span class="new-box">
<span class="new-label">Novo</span>
</span>
<div class="shop_desc">
<h3><?php echo $nome; ?></h3>
<span class="actual"><?php echo $preco; ?></span><br>
</div>
</a></div>
<?php }?>
depends of what path contains the $foto var. If is the absolute path, you have to retrive the relative path.
Try also to append an / or an http[s] in front of the path
<img src="/<?php echo $foto;?>">
So it would be : //path/to/photo
As I can see it in your comment, your image paths contain spaces, so a possible solution can be to use urlencode() before echoing them.
Try passing full path to img tag like http://localhost/xyz/images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg.
Replace "localhost/xyz" with your website directory path.

Show title when I hover image connected to mysql using php

I want to show the image title when hovered to the image connected to mysql using php.
Here are the code I used.
<div class="galleryko">
<?php $data = mysql_query("SELECT * FROM tbl_gallery_featured")?>
<div class="lalagyan1">
<?php while($row = mysql_fetch_assoc($data)):?>
<div class="lalagyan">
<div id="wew">
<img src="admin/featured/<?php echo $row['photo']?>" style="width:150px; height: 150px;"/></br>
</div>
</div>
<?php endwhile?>
</div>
</div>
Then I tried to insert a TITLE inside the code of
<img src="admin/featured/<?php echo $row['photo']?>" style="width:150px; height: 150px;"/></br>
But when I hover the images after I did, what happened was, all images are entitled with SOMETEXT, Now I want to show the TITLE of an IMAGE seperately.
Some one please solve my problem,. Thank you in advance! :)
Remove title="SOMETEXT" and add something like this to img tag alt="$row['title']"
<img src="admin/featured/<?php echo $row['photo']?>" style="width:150px; height: 150px;"/>

Categories