Including bootstrap and js in php - javascript

I need a fresh pair of eyes to look at this!
I took code directly from one of of my old fiddles https://jsfiddle.net/RachGal/fs9u6mwe/1/ to display photos in a college galley site. However it only shows one. When i include bootstrap and the function in my php it doesn't seem to read it! Why could this be?
My php looks like this
<?php
echo "<html><head><meta charset='utf-8'>";
echo "<script type='text/javascript' src='scripts/bootstrap.js'></script>";
echo"<link rel='stylesheet' type='text/css' href='css/style.css'>";
include "scripts/show.php";
echo" <title>Gallery Display</title></head><body>";
echo "<header>";
echo "<h1>The Ultimate Gallery Compiler</h1>";
echo "<div id='menu'><a class='head' href='index.html'>Upload Photo</a> <a class='head' href='gallery.html'>Browse Gallery</a></div>";
echo "</header>";
echo "<div id='content'>";
echo "<h2>Browse Gallery</h2>";
$subfolder = $_POST["category"];
if ($subfolder == "0"){
echo("Please <a href='gallery.html'>go back</a> and select a category");
echo "</div><br><br>";
echo "<footer>";
echo "<p class='foot'>© Copyright 2015-2016 MMA2 Rachel Gallen, Ysabel Pheifer and Rebecca Merrigan.</p>";
echo "</footer>";
exit();
}
$countcontents = file_get_contents("categories.txt"); //read file to get count
$countarray = explode('*', $countcontents); //get count of each category into an array
$categories = array("fashion", "music", "sports", "technology", "animals", "health", "other");
//output title according to if the gallery has images in it or not
for($i=0; $i< count($countarray); $i++)
{
if ($subfolder == $categories[$i]){
if (intval($countarray[$i]) == 0) {
echo "<h3>No images have been uploaded for the " .$subfolder. " category yet</h3>";
}
else
{
echo "<h3>Here are the images for the " .$subfolder. " category</h3>";
echo "<p>There are ".$countarray[$i]." photos in this category</p><br>";
}
}
}
$folder = "images/".$subfolder."/";
// Open the appropriate subfolder, and display its contents.
// http://php.net/manual/en/function.opendir.php
// also referenced https://www.youtube.com/watch?v=nGLi4ykt__0
if ($dir = opendir($folder)) {
$images = array();
while (false !== ($file = readdir($dir))) {
if ($file != "." && $file != "..") {
$images[] = $file;
}
}
closedir($dir);
}
echo '<div id="slider">';
echo "<ul id='slides'>";
foreach($images as $image) {
echo '<li class="slide"><img src="';
echo $folder.$image;
echo '" alt=""/></img></li>';
}
echo "</ul>";
echo '</div>';
echo "<p>&nbsp</p><a href='gallery.html'>Reselect</a>";
echo "</div>";
echo "<footer>
<p class='foot'>© Copyright 2015-2016 MMA2 Rachel Gallen, Ysabel Pheifer and Rebecca Merrigan.</p>
</footer>";
echo "</body></html>";
?>
Any help would be appreciated!
by the way the javascript is
//Reference https://jsfiddle.net/RachGal/fs9u6mwe/1/
$(document).ready(function() {
//INDEX IMAGES SLIDER
$(function slider() {
//configuration
var width = 360;
var speed = 1000;
var pause = 3000;
var current = 1;
//cache DOM
var $slider = $('#slider');
var $slides = $slider.find('#slides');
var $slide = $slides.find('.slide');
setInterval(function() {
//move image the defined width and speed to the left
$slides.animate({
'margin-left': '-=' + width
}, speed, function() {
//count number of slides and loop back to first from last
current++;
if (current === $slide.length) {
current = 1;
$slides.css('margin-left', 0);
}
});
}, pause);
});
}
);

You have not included jQuery in your pages, you are using jQuery in your script but it is not loaded at all.
A nice way to find these things out is using the developer bar by pressing F12 when using chrome, then at network you can see which files were loaded and in console if there were any javascript errors.

Related

How do I hide the load more button for this jquery code

I am trying to make a website but I am very new to the jquery stuff and I added jquery load more comment into my website
My question is, I have a load more button that works the way I intended it to work however when all the data are loaded or when there is no comment I can't seem to get the load button to turn hidden
//jquery script
<script>
$(document).ready(function() {
var commentCount = 20;
var qidNow = "<?php echo $qid; ?>";
$("button").click(function() {
commentCount = commentCount + 20;
$("#comments").load("includes/load-comments.inc.php", {
commentNewCount: commentCount,
qid: qidNow
});
});
});
//load-comments page
<?PHP
require 'dbh.inc.php';
include 'function.inc.php';
$commentNewCount = $_POST["commentNewCount"];
$qid = $_POST["qid"];
$count = 0;
$sqlComment = "SELECT comment, commentTime, commenterId FROM comments WHERE commentOn = ?
LIMIT ?";
$stmtComment = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmtComment, $sqlComment)) {
header("Location: ../viewtopic.php?error=sqlerror4");
exit();
} else {
//bind parameter to the placeholder
mysqli_stmt_bind_param($stmtComment, "ii", $qid, $commentNewCount);
//run parameter inside database
mysqli_stmt_execute($stmtComment);
$commentData = mysqli_stmt_get_result($stmtComment);
}
if (mysqli_num_rows($commentData) > 0) {
while ($row = mysqli_fetch_assoc($commentData)) {
$count++;
echo "<div class='individualComment'>";
echo "<div class='commentCount'> คอมเม้นที่" . $count . "</div>";
echo "<div class='actualComment'>" . $row['comment'] . "</div>";
echo "<div class='commentDateBx'>" . dateReformat($row['commentTime']) . "</div>";
echo "<div class='commenterIdBx'>ID :" . $row['commenterId'] . "</div>";
echo "</div>";
}
}else {
echo "There is no comment yet";
}

Woocommerce Product Image Flip on Hover

I am working with a wordpress theme called X theme. My lead dev guy bailed and this function is not working. The purpose of it is to flip to the first image in that products gallery when a mousein/out event occurs. The query is looking for a proceeding post ID which is not there or doesn't meet the criteria for the query. So instead I would like it to simply get the image a better way because this doesn't work consistently.
function x_woocommerce_shop_thumbnail() {
GLOBAL $product;
$stack = x_get_stack();
$stack_thumb = 'entry-full-' . $stack;
$stack_shop_thumb = $stack_thumb;
$id = get_the_ID();
$rating = $product->get_rating_html();
woocommerce_show_product_sale_flash();
echo '<div class="entry-featured">';
echo '<a id="id'.$id.'" value="'.$id.'" href="'.get_the_permalink().'">';
echo get_the_post_thumbnail( $id , $stack_shop_thumb );
global $wpdb;
foreach($wpdb->get_results('SELECT ID FROM wp_posts WHERE post_parent = "'.$id.'" AND post_type = "attachment" ORDER BY ID DESC LIMIT 1') as $key => $row){
$file = '_wp_attached_file';
$childId = $row->ID;
global $wpdb;
$query = 'SELECT meta_value FROM wp_postmeta WHERE meta_key = "'.$file.'" AND post_id = "'.$childId.'"';
$otherImage = $wpdb->get_var($query);
if($otherImage != ''){
echo '<img id="otherImage" src="/wp-content/uploads/'.$otherImage.'"/>';
}
}
if ( ! empty( $rating ) ) {
echo '<div class="star-rating-container aggregate">' . $rating . '</div>';
}
echo '</a>';
echo "</div>";
}
The java & jQuery for the flip (is running in the footer of theme)
//Product Hover Image Switch
jQuery(document).ready(function() {
jQuery('[id^=id]').mouseover(function(){
if(jQuery(this).children('#otherImage').attr('src') != ''){
jQuery(this).fadeTo(200, 0, function(){
var source = jQuery(this).children('#otherImage').attr('src'),
original = jQuery(this).children('.wp-post-image').attr('srcset');
jQuery(this).children('.wp-post-image').attr('srcset', source);
jQuery(this).children('#otherImage').attr('src', original);
}).fadeTo(200, 1);
}
});
jQuery('[id^=id]').mouseout(function(){
if(jQuery(this).children('#otherImage').attr('src') != ''){
jQuery(this).fadeTo(200, 0, function(){
var source = jQuery(this).children('#otherImage').attr('src'),
original = jQuery(this).children('.wp-post-image').attr('srcset');
jQuery(this).children('.wp-post-image').attr('srcset', source);
jQuery(this).children('#otherImage').attr('src', original);
}).fadeTo(200, 1);
}
});
});

How can I limit the number of images shown per page?

I have a certain number of images that are displaying per page. I want to set a maximum limit for the number of images shown on any page, for example setting a property such that no more than eight are shown. I've written this logic in PHP but I'm still seeing all images showing on any given page, ignoring any limit I set. The code:
$counter = 0;
foreach ($device as $value) {
$entry = $value;
echo "<head>";
echo '<script type="text/javascript">',
'window.setInterval(function() { ',
"document.getElementById('$counter').src='/latimage.php?&dev=$entry&random='+new Date().getTime();",
'},1000)',
'</script>';
echo "</head>";
echo "<body onLoad='setTimeout('refresh()',1000)'>";
echo "<td>$entry<img id= '$counter' width='100%' height='auto'></img></td>";
$counter = $counter + 1;
if ($counter == 4 || $counter == 8) {
echo " <tr>";
}
the best way is to fetch only 8 images from database instead of fetching all images at once.Use pagination to set limit and offset for each page.
You need to add a $_GET['variable'];
Something like this,
if(isset($_GET['last_image'])) {
$last_image = $_GET['last_image'];
}
else {
$last_image = 0;
}
$device[] = //however you get the images
$size_of_array = count($device);
for ($counter = $last_image; $counter < $counter + 8 && $counter < $size_of_array; $counter++) {
$entry = $device[$counter];
echo "<head>";
echo '<script type="text/javascript">',
'window.setInterval(function() { ',
"document.getElementById('$counter').src='/latimage.php?&dev=$entry&random='+new Date().getTime();",
'},1000)',
'</script>';
echo "</head>";
echo "<body onLoad='setTimeout('refresh()',1000)'>";
echo "<td>$entry<img id= '$counter' width='100%' height='auto'></img></td>";
}
Then next button
echo 'Next';
This is the basic idea behind a pagination.

Fancybox issue, need a hand

I made a gallery with images fetched from DB and using Fancybox for displaying it. I have some articles that are the same, just diferent color and I display just one and underneath color boxes for changing the color.
The problem is that when I click on the button to change the color, picture changes, Fancybox on click displays first picture, not the Current one
Part of the code:
JS:
function changeImage(element,id){
var img=document.getElementById(id).src=element;
return false;
}
PHP:
while($row = mysql_fetch_array($sql)){
$prikaz =$row['prikaz'];
$id = $row['id'];
$ime = $row['ime'];
$thumb = $row['thumbs'];
$boja = $row['boja_id'];
$slicka = $row['slika'];
$spec = $row['tekst'];
if ($prikaz == 1){
echo "<table style ='display: inline' align='center'>";
echo "<tr>";
echo "<td><a class='fancybox-effects-a' href='$slicka' ><img id='$id' src='$thumb' alt='' /></a></td>";
echo "</tr>";
echo "<tr><td>";
echo "Boja: ";
$bsql = mysql_query ("SELECT muski.tekst, muski.id,muski.thumbs,boja.bslika FROM boja INNER JOIN muski ON muski.boja_id = boja.id WHERE muski.ime = '$ime' " );
while($res = mysql_fetch_array($bsql)){
$slicica = $res['thumbs'];
$muid = $res['id'];
$kockica = $res['bslika'];
echo "<button id = 'boja' onclick =changeImage('$slicica','$id')><img src= $kockica ></button>";
}
echo "</br>";
echo nl2br($spec);
}
echo "</td>";
echo "</tr>";
echo "</table>";
I found the solution.... I modified js script to change the parent href of img... It works...
function changeImage(element,id,staza) {
var img = document.getElementById(id);
img.src= element;
img.parentNode.href=staza;
return false;
}
Firebug your Fancy Box pop-up and inside the you have to change back ground image as well

Jquery rotating image banner first image issue

I have created an rotating image banner module for an in house CMS. I did not write all the jquery for this and that's why I'm a little confused.
Basically the problem is the first image displayed in the banner after a page reload does not fade out like the rest of the images do. I understand that this probably because it is the default image loaded and is not part of the loop that's causing the image banner to rotate. The banner can be seen here: http://www.easyspacedesign.com/craig/dentalwise/
Notice how the first image after a reload sort just jumps to the next image but then all he images afterwards smoothly fade in and out.
How do I grab that first image after a reload and make it fadeout like rest?
here is the code:
<script type="text/javascript">
<!--
var doLooop = true;
$(document).ready(function(){
setInterval("loop()",5000);
});
function loop(){
if(!doLooop){ return; }
var $total = parseInt($("input[name=total_slides]").val());
var $id = parseInt($("a._active").attr("rel"));
var $new = $id+1;
if($new>$total){$new=1;}
changeSlide($new);
}
function changeSlide($id){
// Prepare selectors
var $total = $("input[name=total_slides]").val();
var $txtSlt = "#_slideText_"+$id;
var $imgSlt = "#_slideImg_"+$id;
var $active = $("a._active").attr("id");
var $new_img_href = "#animation_selectors a:nth-child("+$id+") img";
var $new_active = "#animation_selectors a:nth-child("+$id+")";
// Hide active images and text
$(".slideImg").css("display","none");
$(".slideTxt").css("display","none");
// Display selected images and text
$($txtSlt).fadeIn(1200);
$($imgSlt).fadeIn(1200);
$($txtSlt).delay(2500).fadeOut(1200);
$($imgSlt).delay(2500).fadeOut(1200);
// Update active anchor image
$("a._active img").attr("src","<?php echo ROOT; ?>Images/StyleImages/off.png");
$("a._active").removeClass("_active");
$($new_img_href).attr("src","<?php echo ROOT; ?>Images/StyleImages/on.png");
$($new_active).addClass("_active");
}
$(function(){
$("#animation_selectors a").click(function(e){
e.preventDefault();
var $id = $(this).attr("rel");
doLooop = false;
changeSlide($id);
});
});
-->
</script>
<div id="animation">
<div id="animation_slides">
<?php
$img_sql = "SELECT strImageUrl FROM tbl_mod_Animation ORDER BY intAnimationID";
if($img = $db->get_results($img_sql)){ $i=1;
foreach($img as $img){
if($i!=1){ $display = " style=\"display:none;\""; } else { $display = ""; }
echo "<div id=\"_slideImg_$i\" class=\"slideImg\" $display><img src=\"".ROOT."Images/Uploads/Slides/".$img->strImageUrl."\" alt=\"\" /></div>";
$i++;
}
}
?>
</div>
<div id="animation_text">
<?php
$text_sql = "SELECT strText FROM tbl_mod_Animation ORDER BY intAnimationID";
if($text = $db->get_results($text_sql)){ $i=1;
foreach($text as $text){
if($i!=1){ $display = " style=\"display:none;\""; } else { $display = ""; }
echo "<div id=\"_slideText_$i\" class=\"slideTxt\" $display>".$text->strText."</div>";
$i++;
}
}
?>
</div>
<div id="animation_selectors">
<?php
for($x=1;$x<$i;$x++){
if($x==1){
?><a id="slide_opt<?php echo $x; ?>" href="#" rel="<?php echo $x; ?>" class="_active"><img class="slideOpt" src="<?php echo ROOT; ?>Images/StyleImages/on.png" alt="" /></a><?php
} else {
?><a id="slide_opt<?php echo $x; ?>" href="#" rel="<?php echo $x; ?>"><img class="slideOpt" src="<?php echo ROOT; ?>Images/StyleImages/off.png" alt="" /></a><?php
}
}
echo "<input type=\"hidden\" name=\"total_slides\" value=\"".($i-1)."\" />";
?>
</div>
</div><!--end of animation-->
<?php
?>
changeSlide() sets up each slide to fade in and then fade out in 2.5 seconds. loop() calls changeSlide() every 5 seconds and passes the id of the next slide to be shown. The problem is that the first slide isn't set up the same way on page reload. It's probably just statically written on the page with the _active class.
You'd be better off, instead of setting a delay to fade each slide out after 2.5 seconds, to pass in both the previous and next slide to the changeSlide function and then fade out the previous and fade in the next.
function loop() {
...
changeSlide($id, $new);
}
and then in changeSlide:
function changeSlide($prev, $next) {
...
var $prevTxtSlt = "#_slideText_" + $prev;
var $prevImgSlt = "#_slideImg_" + $prev;
var $nextTxtSlt = "#_slideText_" + $prev;
var $nextImgSlt = "#_slideImg_" + $prev;
...
$($prevTxtSlt).fadeOut(1200);
$($prevImgSlt).fadeOut(1200);
$($nextTxtSlt).fadeIn(1200);
$($nextImgSlt).fadeIn(1200);
}

Categories

Resources