I am developing a gallery website where users can visit images that other people have shared. I have created the gallery and images can be viewed using thumbnails and the images upload from the right of the previsous image. If an image is at the edge of the page the next image will go in the row beneath it. I use this code to do this:
<?php
mysql_connect("localhost","root","");
mysql_select_db("pardeepsandhu");
$res= mysql_query("select * from images");
$row=mysql_fetch_array($res)
?>
<div id="w">
<div id="content">
<div id="images"><?php while ($row=mysql_fetch_array($res)){?>
<img src="<?php echo $row["Image"]; ?>" height="134.1175" width="134.1175" border="5" alt="turntable" />
<?php } ?>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
$('#images a').lightBox();
});
</script>
However, i am now trying to get a voting system set up. At the bottom of each image there would be a button which will give an image a like. The button works however the images, with the buttons, are being laid out differently. All the images appear one beneath the other, it looks like they are in on column. I don't want this to happen as space will be wasted. This is the code with a button:
<div id="w">
<div id="content">
<div id="images"><?php while ($row=mysql_fetch_array($res)){?>
<img src="<?php echo $row["Image"]; ?>" height="134.1175" width="134.1175" border="5" alt="turntable" />
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="button" id="button" value="Like this image" />
</form>
<?php } ?>
How do I get the images to load like they did before, so that they appear in rows rather than in one column. Can anyone help me?
To achieve a horizontal layout, you will need to use the css "display:inline-block;" on all of your image / link containers. If I were you, I would have another div which contains all the image and voting info. Also, please make sure you are closing all of your divs as this can dramatically change your layout.
Something along the lines of this should get them horizontal.
<div id="pic" style="display: inline-block;">
<img src="">
<form></form>
</div>
http://jsfiddle.net/u9gSD/
Related
I need some help, I have a repeat region which displays pics from a database, when I click on the image I would like to go to another page where there is a photo gallery to display my pictures bigger.
My problem, no matter which thumb I click I get the same set of pictures from the database, which is usually the last thumb listed.
I am new to php, so i am wondering if anyone can help me, thank you.
Code for thumb page
`
<?php do { ?>
<div class="display-property-pic">
<input type="image" id="imageIn1" src="upload/images/<?php echo $row_repeatRegion['thumb']; ?>" alt="Submit" width="100" height="100" ><input name="picHid" type="hidden" value="<?php echo $row_repeatRegion['property_pic1']; ?>">
</div>
<?php } while ($row_repeatRegion = mysqli_fetch_assoc($repeatRegion)); ?>
`
Code for Gallery page
if(isset($_POST['picHid'])){
$pic = $_POST['picHid'];
}
mysqli_select_db($wiplisttest, $database_wiplisttest);
$query_getPics = "SELECT photos.photo_id, photos.pic1, photos.pic2, photos.pic3 FROM photos WHERE photos.property_pic1 LIKE '%$pic%'";
$getPics = mysqli_query($wiplisttest, $query_getPics) or die(mysql_error($wiplisttest));
$row_getPics = mysqli_fetch_assoc($getPics);
$totalRows_getPics = mysqli_num_rows($getPics);
<div class="album">
<div class="description">fixed images</div>
<ol>
<?php do { ?>
<li>
<h4><?php echo "Pic"." ".$row_getPics['pic3']; ?></h4>
<div class="description">Salzburg, Austria</div>
<a href="upload/images/<?php echo $row_getPics['pic3']; ?>">
<img src="upload/images/<?php echo $row_getPics['pic2']; ?>" />
</a>
</li>
<?php } while ($row_getPics = mysqli_fetch_assoc($getPics)); ?>
</ol>
</div>
As you have stored images info in database, there should be id assigned to each image, so when you click on any specific image, get id of that image and retrieve that image on another page using the id.
<div class="fotorama" data-width="700" data-ratio="700/467" data-max-width="100%" align="center" data-arrows="true" data-click="false" data-swipe="false" data-autoplay="2000" data-nav="thumbs">
<?php
$query="select * from released_movies" ;
$queryr=$con->query($query);
while($row=$queryr->fetch_assoc()) { ?>
<div>
<a href="single.php?id=<?php echo $row['rel_id'];?>">
<img u="image" src="../AbaamAdmin/Released_Movies/<?php echo $row['rel_movies_pics'];?>" />
</a>
</div>
<?php }?>
</div>
I need to create a fotorama gallery slideshow with thumbnails of the larger image. But by giving the above code, no image appears as thumbnail instead I got only a thumbnail border. How I will get the thumbnail image there dynamically. Thanks in advance.
I'm an ammature when it comes to webdesigning, I sort of ctrl+c > ctrl+v all of the time trying to learn.
At the moment I'm making a webapplication for selecting cushions on a couch.
I created a page where you can click on a color to see the cushions in that specific color, but I would like to change the color of the base of the couch also.
In short: I would like to place 2 png images on top of each other and be able to change them individually by clicking on colors.
My code for now:
<body>
<div id="page">
<div id="gallery">
<div id="panel"><img id="largeImage" src="images/image_01_large.png"/>
<div id="thumbs">
<img src="images/image_01_thumb.png" alt="Lime Green"/>
<img src="images/image_02_thumb.png" alt="Burgundy"/>
<img src="images/image_03_thumb.png" alt="Cobalt Blue"/>
</div>
<script>
$('#thumbs').delegate('img', 'click', function () {
$('#largeImage').attr('src', $(this).attr('src').replace('thumb', 'large'));
$('#description').html($(this).attr('alt'));
});
Okay, so what I am trying to achieve is a "News Feed" type of thing with PHP and a MySQL database. I have the database and tables setup, and a CMS setup that inserts info into the database, and have successfully called individual rows of the table into my HTML layout using the SELECT statement.
Now, what I am trying to do is have a home page, which contains 12 divs, each one being an image that links to an individual post page, and dynamically generated from my table in DESC order. That way, the 12 most recent designs are displayed on the homepage.
Then, I want to achieve the same type of thing except on a page that is sorted by category, which I am assuming would be done by adding a WHERE category=categoryname to my SELECT statement. Just hoping someone with more knowledge could give me some guidance on how to proceed with this.
Here's my HTML (I inserted Needs to be dynamically generated in the links and img src):
/* Other relevant Code */
<div class="homeContent">
<div class="newsItems">
<div class="newsItem1">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem2">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem3">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem4">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem5">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem6">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem7">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem8">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem9">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem10">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem11">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
<div class="newsItem12">
<img src="**Needs to be dynamically generated**" alt="" class="newsItem" />
</div>
</div>
</div>
I haven't gotten very far with the PHP for this part, as I am not sure which direction to go, and I have slowly learned that if you choose the wrong direction with PHP it usually involves starting over. Thanks in advance for any help!
Long Story Short, how can I get the img src and links to be dynamically generated into these predefined DIVs from a MySQL table using PHP, and get them to be in DESC order?
The following code will take the data from your database and display a new <div>, link, and image.
Image.php:
<?php
$query = "SELECT id, link, image FROM images ORDER BY id DESC";
?>
<html>
<body>
<?php while($row = mysql_fetch_assoc($query)): ?>
<div class="NewsItem<?php echo $row['id']; ?>">
<img src="<?php echo $row['image']; ?>" alt="" class="newsItem" />
</div>
<?php endwhile; ?>
</body>
</html>
This assumes you have a table with the following columns:
ID (AUTO INCREMENT) INT
image TINYTEXT - URL to image file
link TINYTEXT - Link to where you want the link to go.
This answer assumes you have the following:
A MySQL connection in PHP (here, this is stored in the $sql variable).
image_src, url, and created_at columns in your MySQL table (we'll call the table my_table).
Querying for Everything
First off, let's go over the query.
We want to get all the data for all twelve rows at the same time so we don't have to query multiple times. We also want everything ordered in a descending fashion, which is where created_at comes into play.
It could look something like this:
SELECT m.image_src, m.url, m.created_at
FROM my_table AS m
ORDER BY m.created_at DESC
LIMIT 12
Let's store this query in a variable. We'll make it simple and call it $query
$query = /* The query we just wrote above */
Displaying the Results
Now we just have to figure out how to make the result look nice. I'll assume you know how to run the query, seeing how you've managed it already.
Looking at your example, we want each result to be in it's own div element, with a unique class attribute. I would recommend making those into ids instead, since they will be unique. We can add a newsItem class to each one instead.
To do what we want, we'll create a while loop to iterate over each row and print out the appropriate HTML. It could look like this:
<div class="newsItems">
<?php
$result = $sql->query($query);
$count = 0;
while(null !== ($r = $result->fetch_assoc()): ?>
<div id="newsItem<?php echo ++$count; ?>" class="newsItem">
<img src="<?php echo $r['image_src']; ?>" alt="" />
</div>
<?php
endwhile;
?>
</div>
A Couple of Things
Take careful notice of the while condition. With new versions of PHP, it is important that you compare the $r variable against a null value. It used to be possible to use false instead, but now that it isn't, a statement like this one will throw an error:
while(false !== ($r = $result->fetch_assoc())):
Be careful with your statements.
Note how we only put the newsItem class on the div elements. Because the a and img tags are inside of the div, you can select either of them using .newsItem a or .newsItem img in your stylings.
If you have a series of unique classes, it is better to make them ids than classes for clarity. There is no point in having a class that only gets used once.
Enjoy and good luck with your project!
I am rendering with php some amount of images, but also i render the a href="" - the images area changing when they are fading, but the url are the same.
How can I change the url and the image together?
JQuery Cycle
The jquery Cycle plugin can cycle any any elment. So the easy way to do this is to just wrap each image with a hyperlink:
http://jsfiddle.net/lucuma/MV9S5/
<div id="slideshow">
<img src="img1.jpg" />
<img src="img2.jpg" />
<img src="img3.jpg" />
</div>
$('#slideshow').cycle();
Additionally you can use your slide attributes if perhaps you have a title you want updated that is outside of the sliders. You'd use the after event. The following code updates the h1's hyperlink after each slide changes. It sets the text to be the title of the img on the slide. Because my images are wrapped in a hyperlink, I need this line var $cur = $('img', currSlideElement) to get to the img element of the slide.
Demo: http://jsfiddle.net/lucuma/dsK9S/2/
<h1 id="title"></h1>
<div id="slideshow">
<img src="img1.jpg" />
<img src="img2.jpg" />
<img src="img3.jpg" />
</div>
$('#slideshow').cycle({
after:function(currSlideElement, nextSlideElement, options, forwardFlag) {
var $cur = $('img',currSlideElement);
$('#title a').text($cur.attr('title'));
$('#title a').attr('href',$cur.attr('src')).text();
}
});
jQuery solution:
$(yourImage).attr('src', 'newImageUrl');
If you are trying to implement a slider. Try nivo.