I want the image to automatically be in horizontal, Should I put another div? because the picture will be save automatically by their position
And here's my CSS:
.row{
display: block;
height:auto;
width:auto;
}
.box_img2{
width: 20px;
padding : 5px;
margin-bottom:5px;
background-color:white;
height:30px;
float:center;
}
And here's my PHP:
<?php
include('../connection/connect.php');
$result = $db->prepare("SELECT * FROM candposition ORDER BY posid ASC");
$result->bindParam(':userid', $res);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$dsds=$row['posid'];
$resulta = $db->prepare("SELECT sum(votes) FROM candidates WHERE posid= :a");
$resulta->bindParam(':a', $dsds);
$resulta->execute();
for($i=0; $rowa = $resulta->fetch(); $i++){
$dsada=$rowa['sum(votes)'];
}
echo '<div style="margin-top: 18px;">';
echo '<strong>'.$row['pos_name'].' '.'</strong><br>';
$results = $db->prepare("SELECT * FROM candidates,student WHERE candidates.idno=student.idno AND posid= :a ORDER BY votes DESC");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
if($dsds=='Commissoner'){
echo $rows['prog_id'].$rows['prog_id'].' '.$rows['prog_name'].' = '.$rows['votes'];
}else {
echo "<div class='row'><div class='box_img2'><br>";
echo '<img src="savephp/images/'.$rows['image'].'" width="60" height="70px" />'.' '.$rows['lastname'].', '.$rows['firstname'].'<br>'.' = '.$rows['votes'];
echo '</div>';
}
echo '</div>'.'</div>';
$sdsd=$dsada
?>
<br><br><br><br><br>
<img src="../img/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>
<?php
if ($rows['votes']==0){
echo "<br>";}
else {
echo(100*round($rows['votes']/($sdsd),2)); ?>%<br>
<?php
}
echo '</div>';
}
?>
<?php
}
?>
Here's the image:
I want to be like this
Try this:
.box_img2{
width: 20px;
padding : 5px;
background-color:white;
height:30px;
position: fixed; /* or absolute */
top: 50%;
left: 50%;
margin-top: -15px;
margin-left: -10px;
}
Try going down this path, and looking at things like Boostrap's methods to do thumbnail grids, etc., may help you a lot.
Note, the img CSS is more of an either/or thing...one centers, the other will make it fill the 33% of its container.
<style type='text/css'>
.row:before, .row:after { clear:both; }
.img-container {
float:left;
width:33%;
text-align:center;
}
.img-container img { /* if you want it centered */
display:block; margin:0 auto;
}
</style>
<div class='row'>
<?php for($i=0; $rows = $results->fetch(); $i++) { ?>
<div class='img-container'>
<img src="savephp/images/<?php echo $rows['image'] ?>" width="60" height="70px" />
<?php echo $rows['lastname'] ?>, <?php echo $rows['firstname'] ?><br />
=<?php echo $rows['votes'] ?>
</div>
<?php } ?>
</div>
UPDATE I've updated the code above to give a general idea of putting the images into the page. You can build out the rest of the HTML and conditions as needed. The important thing to note is that if you want 3 images across horizontally, make the width of the .img-container 33%. If you only want 2 horizontally, make the width of the .img-container 50%. They will automatically wrap to the next row. Your code was creating a new <div class="row"> for every single entry, which would put each new entry onto its own line rather than having them layout horizontally.
If you hit points where you want a 100% row, you can just give that a different class with width:100% and it will put itself on its own row.
Again, if you lookup how grids work with Bootstrap 3, it will help you get almost any alignment that you want, and I highly recommend using something like that to get going, and then once you're good at creating layouts...then figure out "how" they do it.
Related
I have an array of images in php that I am trying to display as a gallery. It is working pretty well, except that the first row of the gallery comes out diagonal, with each image slightly below the one before it.
Here is the code I am using:
CSS
.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
display: inline;
width:180px;
height:180px;
}
.gallery:hover {
border: 1px solid #777;
}
.gallery img {
max-height:100%;
max-width:100%;
margin:0 auto;
}
HTML/PHP
<div class="gallery-container">
<?php
$count = 0;
foreach($images as $image) {
echo "<div class='gallery'><a href=''><img src='".$dir.$image."'/></a></div>"; //$dir is the path to the image
if(count % 4 == 0) {
echo "<br>";
}
$count = $count + 1;
}
?>
</div>
Here is a screenshot of the result on the first row:
All the other rows come out fine. Thank you very much for any help.
If you want to do it using float, you would better do that like this:
CSS
.gallery{
margin: 5px;
border: 1px solid #ccc;
float: left;
display: block;
width:180px;
height:180px;
}
.gallery.clear-left{
clear: left;
}
PHP/HTML
<div class="gallery-container">
<?php
$count = 0;
foreach( $images as $image ){?>
<div class="gallery <?php echo( 0 == $count % 4 ? 'clear-left' : '' );?>">
<a href="">
<img src="<?php echo $dir.$image;?>">
</a>
</div>
<?php
$count++;
}
?>
</div>
But there is an even better solution to this, called flex:
Instead of br element render "clear" div
<div style="clear:both"></div>
Have you tried starting the count at 1 instead of 0?
Checkout the resulting html. It is likely that you count is off and the br is being put to the dom too often. This fiddle shows that your desired html and css should work.
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<div class='gallery'><a href=''><img src='https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg'/></a></div>
<br>
Though, I would consider not using the br, but instead using a containing div:
like this
I have a main Div which is the "master" of all divs. This div's width is 70% of the page. Inside this div, is another div that contains an image. This div is called mainImg. It is set to absolute positioning and all the rest of the elements are set to absolute as well. All these elements move absolutely relative to the main div.
Here's my code:
PHP/HTML
<?php
$resultSet = $db->query("SELECT * FROM Articles");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
if ($id <= 3)
{
$images = $rows["image"];
$title = $rows["title"];
echo "<div id=main>";
if ($id == 1)
{
echo "<div id=mainImg>";
echo "<img src=$images>";
echo "<div id=mainTitle>";
echo "<h2>$title</h2>";
echo "</div>";
echo "</div>";
}
echo "</div>";
}
}
}?>
CSS
body{
position: relative;
}
#main{
position: relative;
width: 70%;
height: auto;
margin: 1.5% auto;
}
#mainImg{
position: absolute;
width: 65%;
}
#mainImg img{
width: 100%;
}
#mainTitle{
position: absolute;
width: 100%;
height: 25%;
bottom: 0%;
background-color: rgba(100, 0, 0, 0.7);
}
#mainTitle h2{
color: white;
text-align: center;
font-family: sans-serif;
font-size: 120%;
}
My problem that I am facing is that the div inside of mainImg (mainTitle), is not properly rigged inside the image. The div is a semi-transparent block that should fit perfectly on the bottom of the image with 25% height. Instead, the block is coming out of the image a bit. The other problem that I am facing is my text inside this mainTitle div. The text is centered, but not aligned in the middle of the div. I am trying to make the text responsive, with percentages, but whenever I resize the text always goes below the div. How do I fix these three problems? (Rigging the div properly, aligning the text, and keeping the text inside the div at all times for other window sizes?
The semi-transparent div is coming off the edge of the image
When browser is resized, this is what happens to the text
<?php
$res = $db->query("SELECT * FROM Articles");
if( $res->num_rows > 0 ) {
echo "<div id='main'>";/* Open main div outside the loop */
while( $rows = $res->fetch_object() ) {
$id = $rows->id;
if ( $id <= 3 ) {
$image = $rows->image;
$title = $rows->title;
if ( $id == 1 ) {
echo "
<div id='mainImg'>
<img src='$image'>
<div id='mainTitle'>
<h2>$title</h2>
</div>
</div>";
}
}
}
echo '</div>';/* close main div */
}
?>
i have a problem with my stylesheet.
i have repeated div by looping (php)
This is the looping
<div class=content>
<?php $db=new db; $sql=$db->query("SELECT * FROM tbl_news WHERE category='1' ORDER BY 1 DESC LIMIT 0,10"); while($r=$sql->fetch(PDO::FETCH_ASSOC)){ echo '
<div class=box-thread>
<img src="images/galleries/preview_'.$r['img'].'">
<br />
<h1>'.$r['title'].'</h1>
<p align=justify>'.strip_tags(htmlspecialchars_decode(substr($r['contents'],0,200))).'</p>
</div>'; } ?>
</div>
but the problem is showed in the picture, there is missing div there. I dont know why. any div i set to "float:left" so it's auto go to bottom if there is reach the page's width.
This is my css
.content {
width:100%;
margin:auto
}
.box-thread {
width:20%;
background-color:#fff;
margin:2%;
float:left;
min-width:240px
}
.box-thread img {
width:100%;
}
.box-thread p {
padding:5px 20px
}
.box-thread h1 {
padding:0 20px;
font-size:18px
}
Thank you for any help
How to display one by one fadein element from db when using loop for ?
.........................................................................................
When i load page index.php , it's will display 40 element from db,
but i want to apply code to show one by one element fadein , How can i do that ?
use in IE7
.
.
index.php
<?php
for($i=0;$i<40;$i++)
{
$strSQL = "SELECT * FROM products order by id desc Limit $i,1 ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
$products_img_thumbnail_path_grid[$i] = $objResult["products_img_path"];
}
?>
<ul>
<?PHP
for($i=0;$i<40;$i++)
{
?>
<li class="thumbnail" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
<div class="imgWrap" style=" float: left; height: 80px; " >
<a href="xxxxx.php">
<img border="0" src="<?PHP echo $products_img_thumbnail_path_grid[$i]; ?>" width="80" height="80" style=" background-color: #fff; border: 1px solid #aaa; "/>
</a>
</div>
</li>
<?PHP
}
?>
</ul>
Check this answer:
Using CSS for fade-in effect on page load
Basically you want to use css3 animations to apply a fade in effect to the images
var test = $('ul li');
current = 0;
test.hide();
Rotator();
function Rotator() {
$(test[current]).fadeIn('slow').delay(5000).fadeOut('slow');
$(test[current]).queue(function() {
current = current < test.length - 1 ? current + 1 : 0;
Rotator();
$(this).dequeue();
});
}
use above code after the ul section, hope it work for you
.
I am building a site that uses a plugin to create a gallery view a video feed. In the PHP file that generates the gallery view, I added a play button to display on top of the video thumbnails. While the button displays correctly, the plugin applies the video link directly to the thumbnail image, so if a user clicks directly on the button, it does not open the video modal.
<div class="media-thumb videoPreviewBox">
<div class="videoPreview">
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
<img class="playButtonHover" src="<?php echo $this->getThemePath()?>/images/playButtonHover.png">
<img class="playButton" src="<?php echo $this->getThemePath()?>/images/playButton.png">
</div>
</div>
While I'm not sure why there is a closing tag placed where it is, the plugin seems to work fine. I think the issue is that href="#popup_prep" is applied to the image. I tried to wrap the thumbnail image and play button states in < a href="#popup_prep"> (space added to show tag in post), both with and without the href applied to the image.
I'm stumped and don't want to screw anything up. Hoping a PHP person here can point out what I'm doing wrong. Many thanks!
The rest of this post is information I'm including for due diligence, since I'm not sure how much and what context is needed. First the CSS applied to these elements, followed by the full PHP file for the gallery view.
div.videoPreviewBox {
float: left;
display: inline-block;
width: 21%;
margin: 2%;
margin-top: 0%;
}
#media only screen and (max-width: 594px) {
div.videoPreviewBox {
width: 46%;
}
}
#media only screen and (max-width: 300px) {
div.videoPreviewBox {
width: 96%;
}
}
div.videoPreview {
position: relative;
}
img.videoPreviewImg {
width: 100%;
z-index: 1;
}
img.playButtonHover, img.playButton {
position: absolute;
z-index: 5;
top: 50%;
left: 50%;
margin-top: -24px;
margin-left: -24px;
-webkit-transition: opacity .7s ease-in-out;
-moz-transition: opacity .7s ease-in-out;
-o-transition: opacity .7s ease-in-out;
transition: opacity .7s ease-in-out;
}
div.videoPreview:hover img.playButton {
opacity: 0;
}
div.videoPreviewBox p {
margin-top: 2%;
color: white;
line-height: 18px;
}
.player_wrapper{float: left;}
.player{float: left;clear: both;}
.scroller{margin-bottom: 35px; float: left;clear: both; width: 100%;}
.rssIcon{float: left;clear: both;}
.scroll_item{clear: left; float: left;}
.thumb_img{margin-right: 12px; margin-bottom: 25px; float: left; border-color: white; border-width: 2px; border-style: solid; background-color: #dddddd; height: 135px;}
.preview{ width: 600px; }.play_button{padding: 8px; background-color: #e9e9e9; border-color: #c9c9c9; border-width: 1px; border-style: solid; float: right;}
.rssIcon{width: 100%;}
.gallery_thumb{margin-bottom: 12px; margin-right: 12px; }
.gallery_thumb:hover{cursor: pointer;}
.mejs-container{margin-top: 20px!important}
And the full PHP gallery view file:
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$btID = $b->getBlockTypeID();
$bt = BlockType::getByID($btID);
$uh = Loader::helper('concrete/urls');
$rssUrl = $controller->getRssUrl($b);
$textHelper = Loader::helper("text");
$fl = Loader::model('file_version');
$uh = Loader::helper('concrete/urls');
$mh = Loader::helper('media_type','promedia');
$bt = BlockType::getByHandle('promedia_list');
$height = '400';
$width = '600';
$spread = 4;
$playerID = rand(0,777777);
if (count($cArray) > 0) { ?>
<div class="scroller">
<div id="media_galery">
<?php
$t = 0;
for ($i = 0; $i < count($cArray); $i++ ) {
$t++;
$file = $cArray[$i];
$remote = null;
$name = $file->getFileName();
$file_path = BASE_URL.DIR_REL.$file->getDownloadURL();
$ak_d = FileAttributeKey::getByHandle('media_date');
$date = $file->getAttribute($ak_d);
$ak_a = FileAttributeKey::getByHandle('media_artwork');
$image = $file->getAttribute($ak_a);
if($image==null){
$image_path=$uh->getBlockTypeAssetsURL($bt).'/tools/mp3.png';
}else{
$image = File::getByID($image->fID);
$image_path=$image->getURL();
}
$file_src = BASE_URL.DIR_REL.$file->getRelativePath();
$ak_s = FileAttributeKey::getByHandle('media_audio');
$audio = $file->getAttribute($ak_s);
if($audio){
$audio_array = $mh->getMediaTypeOutput($audio);
$audio_path = $audio_array['path'];
$file_src = $audio_path;
}
$video = null;
$ak_s = FileAttributeKey::getByHandle('media_video');
$video = $file->getAttribute($ak_s);
if($video){
$video_array = $mh->getMediaTypeOutput($video);
$video_path = $video_array['path'];
//var_dump($video_array['id']);
$image_path = $mh->getMediaThumbnail($video_array['id'],$video_array['type']);
//$video_src = $video_path.'?width='.$width.'&height='.$height;
//$file_src = $video_src;
if($video_array['type'] == 'vimeo'){
$file_src = 'http://player.vimeo.com/video/'.$video_array['id'];
}else{
$file_src = $video_path;
}
}
?>
<div class="media-thumb videoPreviewBox">
<div class="videoPreview">
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
<img class="playButtonHover" src="<?php echo $this->getThemePath()?>/images/playButtonHover.png">
<img class="playButton" src="<?php echo $this->getThemePath()?>/images/playButton.png">
</div>
</div>
<?php
if($t == $spread){
$t=0;
echo '</tr>';
}
}
for($d=$t;$d<$spread;$d++){
echo '<td></td>';
if($t == $spread){
echo '</tr>';
}
}
?>
</div>
</div>
<div style="display: none;">
<div id="popup_prep">
</div>
</div>
<script type="text/javascript">
/*<![CDATA[*/
$(document).ready(function() {
$('.gallery_thumb').fancybox({
width: 'auto',
height: 'auto',
onClosed: function(){
$('video, audio').each(function() {
$(this)[0].player.pause();
});
}
});
});
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
$('.gallery_thumb').click(function(){
$('#popup_prep').html('');
var html = '';
var path = $(this).attr('alt');
//console.log(path);
var extension = path.substr( (path.lastIndexOf('.') +1) );
if(extension){
switch(extension) {
case 'm4v':
case 'mpeg':
case 'mpg':
case 'wmv':
case 'avi':
case 'mov':
case 'flv':
case 'f4v':
case 'mp4':
html = '<video class="player_box" id="play" controls="controls" src="'+path+'" width="<?php echo $width?>" height="<?php echo $height?>"></video><br style="clear: both;"/>';
break;
case 'mp3':
case 'm4a':
html = '<audio class="audioplayer" id="play" src="'+path+'" controls="controls" type="audio/m4a"></audio><br style="clear: both;"/>';
break;
default:
var iFrame = true;
html = '<iframe title="video player" width="<?php echo $width?>px" height="<?php echo $height?>px" src="'+path+'" frameborder="0" allowfullscreen></iframe>';
}
}
$('#popup_prep').append(innerShiv(html));
if(!iFrame){
var player = new MediaElementPlayer('video,audio');
}
});
/*]]>*/
</script>
<?php
}
if(!$previewMode && $controller->rss) {
?>
<div class="rssIcon">
<img src="<?php echo $uh->getBlockTypeAssetsURL($bt, 'rss.png')?>" width="14" height="14" />get this feed
</div>
<link href="<?php echo $rssUrl?>" rel="alternate" type="application/rss+xml" title="<?php echo $controller->rssTitle?>" />
<br/>
<?php
}
if ($paginate && $num > 0 && is_object($_fl)) {
$_fl->displayPaging();
}
?>
For full context, here is the page.
I'm not exactly a php expert, but I notice some problems in this line of code:
</a><img src="<?php echo $image_path?>" href="#popup_prep" alt="<?php echo $file_src?>" class="<?php echo $playerID?>player_get<?php echo $i?> gallery_thumb" href="<?php echo $file_src?>"/>
First of all, I'm not sure why there is a "/a" there. That is normally the end tag of a hyperlink. (if I put the <> there it disappears from the answer and gets read like html so lets pretend the "" is the same as <>).
Secondly, it looks like you got the stuff inside the quotes for href and alt mixed up. href is the link, alt is the description. Unless you want the description to be the same as the image link, but I would recoment something more fitting such as alt="Play Video".
Thirdly, check the number of spaces in the class. For example, if $playerID="123" and $i=1. The class would be the following: 123player_get1 gallery_thumb (notice the space between $i, or in this example the number 1, and gallery_thumb). Again I might be wrong but I don't think that space should be there and it can be fixed by eliminating the space beside the closing php tag.
Fourthly, you have two href="" in this img tag. Like I said I'm not an expert, but I'm assuming the first one need not be there and probably is causing trouble, as href is the link it will take you to when the image is clicked.
Fifthly, I'm not sure if it really matters or not, but normally an img tag doesn't have a /> at the end, it only requires a >.
Try substituting it for this line of code:
img src="<?php echo $image_path ?>" href="<?php echo $file_src ?>" alt="YOUR DESCRIPTION HERE" class="<?php echo $playerID ?>player_get<?php echo $i ?>gallery_thumb">
*edit: If it works make sure you understand why!