Display image slideshow by using php mysql - php

i have a database named hotel_booking,it contains field named imglinks which stores the link of the images and i am only able to display single image in the site. i want to display a slide show of the images of the respective hotels.
<tr>
<th>NAME OF HOTELS</th>
<th>CATEGORY</th>
<th>DESCRIPTION</th>
<th>ADDRESS</th>
<th>GALLERY</th>
</tr>
<?php
while($row=mysql_fetch_array($query))
{
$f1=$row['name'];
$f2=$row['category'];
$f3=$row['description'];
$f4=$row['address'];
?>
<tr>
<td><?php echo $f1 ?></td>
<td><?php echo $f2 ?></td>
<td><?php echo $f3 ?></td>
<td><?php echo $f4 ?></td>
<td><img src="<?php echo $row['imglinks'];?>" height="200" width="55"></td>
link to image of what i want to achieve

You can use bootstrap to achieve this easily with a few lines of code.
http://getbootstrap.com/javascript/#carousel
Go through this link and if there is any problem let me know :)

Related

How to make sql image clickable on display board

I am trying to make the fetched images on a sql database clickable. They display fine but no-one can click them or download them and I'd like them to be able to. The script is below.
<?php
include_once 'connect.php';
$result = mysqli_query($conn,"SELECT * FROM Leaderboard");
?>
<?php
if (mysqli_num_rows($result) > 0) {
?>
<p>Leaderboard and guest photos as of October 20, 2020. Our apologies to our prior guests.</p>
<table class='table table-bordered table-striped'>
<tr>
<td>Date</td>
<td>Photo</td>
<td>Team Name</td>
<td># of Players</td>
<td>Escape Room</td>
<td>Time</td>
<td>Success</td>
<td>Game Master</td>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row["date"]; ?></td>
<td><?php echo "<img src='/teamphotos/".$row['photo']." ' width='250' height='200'>"; ?>. </td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["players"]; ?></td>
<td><?php echo $row["room"]; ?></td>
<td><?php echo $row["time"]; ?></td>
<td><?php echo $row["win"]; ?></td>
<td><?php echo $row["master"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
}
else{
echo "No result found";
}
?>
Probably you want that if the user left clicks the image, a download of that image starts. For that you only need to wrap an anchor tag <a> around the <img> with the attributes src and download.
<td><?php echo ''; ?></td>
This is related to HTML and not to PHP. Here you can read more about it:
https://www.w3schools.com/howto/howto_html_download_link.asp

create a clickable link in MySQL results

I'm in the process of learning some coding. I am looking to create the results of MySQL results clickable. I would like the name (first and last name) to be "clickable" so they can link to the customer record to view. Thanks in advance for your help!
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Thanks,
If you want clickable first name and last name then you need to add anchor tag with view url like below examples.
Example (send first name and last name separately)
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Better solution is you can send id of user . For example i am asuming you have one column id in customers table then you can pass id like below example
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
Note: You can encrypt id by using some hash methods to securely pass id of user.
Now when you click on these links you will redirect on view page where you can get these id or firstname, lastname by using GET method.
Example
view-record.php
<?php
if(isset($_GET['uid'])) {
$userid = $_GET['uid']; //please add some validation before using this value.
}
?>
You need to use the <a> (anchor) html tag like this:
<table class="list"; >
<tr>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Phone</th>
</tr>
<?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
<tr>
<td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
<td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
<td><?php echo h($customers['email1']); ?></td>
<td><?php echo h($customers['phone1']); ?></td>
</tr>
<?php } ?>
Replace the url http://example.com/... with whatever real url you want to use for the link.

html load picture using web address

I'm getting the web address of pictures on the internet from my database and displaying them back on the page, it is currently displaying the actual web address and not loading the actual picture, is it possible to get the actual picture to be loaded? (on the database the web address of the image is stored as a string)
<tr>
<!--<th>id</th>
<td><?php echo $row['id']; ?></td> -->
<th>Name</th>
<td><?php echo $row['hname']; ?></td>
<th>image</th>
<td><?php echo $row['himage']; ?></td>
<th>Description</th>
<td><?php echo $row['hdesc']; ?></td>
</tr>
What you're looking for is called an img tag. Something like this:
<td><img src="<?php echo $row['himage']; ?>" /></td>
If your image is stored for example in the root in the folder itages, then
<td><img src="/images/<?php echo $row['himage'];?>" /></td>
OR
<td><img src="/images/<?=$row['himage'];?>" /></td>

Image not displaying from table

<?php
$connect = mysqli_connect('localhost', 'root', ' ', ' ');
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();}
$result= mysqli_query($connect, "SELECT * FROM Products WHERE ProductCategory = 'Electronics'");
?>
<table width="500", cellpadding=5 callspacing=5 border=1>
<tr>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Image</th>
<th>Product Description</th>
<th>Product Category</th>
</tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $rows['ProductName']; ?></td>
<td><?php echo $rows['ProductPrice']; ?></td>
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
<td><?php echo $rows['ProductDescription']; ?></td>
<td><?php echo $rows['ProductCategory']; ?></td>
</tr>
<?php endwhile; ?>
</table>
My issue is that the code that I currently have only makes it so that it will run through the database line by line and get the information but when it comes to the images row then it doesn't retrieve anything and my directory is correct as the image is stored in a folder called images that is within the folder the web page is.
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You forgot to close the <p and also missing the "s" in rows
this should be <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
also dont forget to close the <p> tag later
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You're missing a closing > on p before img and subsequently a closing p.
Try:
<td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
You can edit the size of your pictures by using CSS, if photoshop is not a solution.
Instead of
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
Use below code
<td><?php
$productImage = !empty($row["ProductImage"])?$row["ProductImage"]:'no-image.png';
echo "<img src='/images/{$productImage}' />";?>
You're missing the "s" in rows
Try: <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>

Checking the value of all a loops value

I have this loop in PHP that echoes out a table of results,
<table cellspacing="0" cellpadding="3">
<tr>
<td><b>Content Image Title</b></td>
<td><b>Content Image Type</b></td>
<td><b>Headline Image</b></td>
<td><b>Content Image Belongs To</b></td>
<td><b>Date Created</b></td>
<!--<td><b>Uploaded By</b></td>-->
</tr>
<?php $colours = array("#f9f9f9", "#f3f3f3"); $count = 0;?>
<?php foreach ($allContentImages as $contentImages) : ?>
<tr bgcolor="<?php echo $colours[$count++ % count($colours)];?>">
<td><?php echo "<a href='#' class='screenshot' rel='/media/uploads/$contentImages[categoryId]/$contentImages[contentImageName]'>".$contentImages['contentImageName']; ?></td>
<td><?php echo $contentImages['contentImageType']; ?></td>
<td><?php if($contentImages['isHeadlineImage'] == 1){ echo "Y";}else{echo "N";} ?></td>
<td><?php echo $contentImages['contentTitle'] ?></td>
<td><?php echo date("d-m-Y", $contentImages['contentImageDateUploaded']); ?></td>
<td align="left"><a class="delete" href="<?php echo base_url();?>dashboard/deleteContentImage/<?php echo $contentImages['contentImageId'];?>"><img src="/media/images/icons/cancel.png" alt="Delete A Category"/></a></td>
</tr>
<?php
if($contentImages['isHeadlineImage'] == '0') {
echo "<tr bgcolor='red'>";
echo "<td><p>You need to assign a headline image</p></td>";
echo "</tr>";
?>
<?php endforeach; ?>
</table>
I need to check for each content piece with the same title that there is headline image, and if not then echo a new row that is red...but all I get is a new row every time there is an image that is not a headline image. Can anyone help me? I don't mind using javascript if that helps to match the values of the td's? But obviously my attempt is not correct.
It sounds like what you want to do has to be precalculated, since the foreach loop can not know about future content.
Maybe something like this before your foreach statement:
$contentHasHeadlineImage = array();
foreach ($allContentImages as $contentImages) {
if ( $contentImages['isHeadlineImage'] == 1)
$contentHasHeadlineImage[ $contentImages['contentTitle'] ] = true;
}
And then you can use
if (array_key_exists($contentImages['contentTitle'], $contentHasHeadlineImage)) {
// Has headline image...
}
to to verify if a certain title has a headline.
Try my code below:
<table cellspacing="0" cellpadding="3">
<tr>
<td><b>Content Image Title</b></td>
<td><b>Content Image Type</b></td>
<td><b>Headline Image</b></td>
<td><b>Content Image Belongs To</b></td>
<td><b>Date Created</b></td>
<td>Action</td>
</tr>
<?php
$colours = array("#f9f9f9", "#f3f3f3");
$num_colours = count($colours);
$i = 0;
?>
<?php foreach ($allContentImages as $row) : ?>
<tr bgcolor="<?php echo $colours[($i++) % $num_colours]; ?>">
<td><a href="#" class="screenshot"
rel="/media/uploads/<?php echo $row['categoryId']; ?>/<?php echo $row['contentImageName']; ?>">
<?php echo $row['contentImageName']; ?>
</a></td>
<td><?php echo $row['contentImageType']; ?></td>
<td><?php echo $row['isHeadlineImage'] == 1 ? "Y" : "N"; ?></td>
<td><?php echo $row['contentTitle']; ?></td>
<td><?php echo date("d-m-Y", $row['contentImageDateUploaded']); ?></td>
<td align="left"><a class="delete"
href="<?php echo base_url(); ?>dashboard/deleteContentImage/<?php echo $row['contentImageId'];?>">
<img src="/media/images/icons/cancel.png" alt="Delete A Category" />
</a></td>
</tr>
<?php if ( $row['isHeadlineImage'] == 0 ): ?>
<tr bgcolor="red">
<td colspan="6"><p>You need to assign a headline image</p></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
While tidying your code, I found an unclosed a href in the first column. For the special extra row, I add colspan. I assume $row['isHeadlineImage'] have value only 1 or 0 (integer or boolean).
I also found out that you access array key without using quote. It can become potential bug in the future.
Write the code in tidy indentation and consistent when using block or echoing the php variable will help you found the bug quickly. Also, inspect the result in browser using Firebug in firefox or Web Inspector in Safari and Google Chrome to see if the page structure is like you want to have, all the tag is balanced and closed in right place.

Categories