I have following script to show the ratings for courses. But it is working properly for pagination first page showing 5 stars, when it comes to second page it showing 10 stars. Code is like below,
<div class="ft-item">
<div class="rating_<?php echo $row->courseId;?>">
</div>
<script>
$('.rating_<?php echo $row->courseId;?>').raty({
starOff : '<?php echo base_url()?>public/images/star/icon-star-2.png',
starOn : '<?php echo base_url()?>public/images/star/icon-star-1.png',
starHalf: '<?php echo base_url()?>public/images/star/icon-star-3.png',
readOnly : true,
half : true,
score : <?php echo $r;?>,
space : true
});
</script>
First page course image
In this course five stars are displaying and located in first page.
Second page course image
In this course 10 stars are displaying and located in second page.
Is the above script is not binding in second page?
As you are calling the pagination via ajax, then you need to call your script after ajax response in the success function too. But the problem is that your score needs to be specific to every book/item, you need to change the
score : <?php echo $r;?>
and
$('.rating_<?php echo $row->courseId;?>')
and get the score via javascript rather than php and move the function into ajax success. Now to get the data from the javascript and removing php you need to use data attributes for this purpose add the rating like data-rating=<?=r?> whie populating the html via php and then use .each and iterate all elements and get the respective data-rating attribute in javacript via $(element).data('rating') and assign to the rate option. You can see the below example how to populate the rating based on the data attrbutes you just need to copy this javascript and update you html accordingly and you are done.
$('.rating').each(function() {
var ele = $(this);
$(ele).raty({
starOff: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.8.0/images/star-off.png',
starOn: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.8.0/images/star-on.png',
starHalf: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.8.0/images/star-half.png',
readOnly: true,
half: true,
score: ele.data('rating'),
space: true
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/raty/2.8.0/jquery.raty.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/raty/2.8.0/jquery.raty.js"></script>
<div class="ft-item">
<div class="rating" data-rating="3"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="4"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="2"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="1"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="5"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="4"></div>
</div>
<div class="ft-item">
<div class="rating" data-rating="4"></div>
</div>
Related
I am implementing a page on which when page loads, the slideshow starts. The pictures for that slideshows are coming form back-end(database). Each picture has its own timer as there are some pictures with the content while some with only heading or logos. At present, I have the same time interval set to each pictures, but now I want to set the time intervals according to their values in database.
here is the code that I have for now with the same time interval:
index.php
<section class='images'>
<? foreach($model->slides as $slide){ ?>
<div class='image'>
<img class='image' src="<?= $slide->image ?.'/pictures/'.$slides->image : '' ?>">
</div>
<? } ?>
</section>
<script type="text/javascript">
$(document).ready(function(){
$('.images').slick({
slidesToShow: 1,
autoplay: true,
autoplaySpeed: 10000,
});
});
</script>
In indexController.php(Controller)
public function index(Array $params = []){
$this->view->slides = \Model\Slide_Picture::getList(['orderBy'=>"image_order asc"]);
$this->loadView($this->view);
}
My table 'slide_images' consist of 3 fields: image, image_order and timer.
As mentioned earlier, this code helps me to get the image slideshow with the time interval of 10s, but now I want to set it different for each images. Say for example, there are 3 images in the database, Picture 1 has a timer value 30s, picture 2 has that of 10s, and picture 3 has value of 40s. So is this possible? If yes, how can I achieve it. Thanks in advance. Appreciate the help.
You would need to add your timing to the database for each image, then once you do that you can return the timing value, and use it in a data attribute. (seems you have done that timer)
Then utilise the afterChange event to get the value and then dynamically change the autoplaySpeed speed.
Below is an example, you would need to integrate it.
$(document).ready(function() {
var images = $('.images');
images.slick({
slidesToShow: 1,
autoplay: true,
autoplaySpeed: 1000,
}).on("afterChange", function(e, slick) {
var slideTime = $('div[data-slick-index="' + slick.currentSlide + '"]').data("timer");
images.slick("setOption", "autoplaySpeed", slideTime);
});
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" />
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<section class='images'>
<div class='image' data-timer="2000">
<img class='image' src="http://via.placeholder.com/350x150">
</div>
<div class='image' data-timer="100">
<img class='image' src="http://via.placeholder.com/350x150">
</div>
<div class='image' data-timer="1000">
<img class='image' src="http://via.placeholder.com/350x150">
</div>
<div class='image' data-timer="3000">
<img class='image' src="http://via.placeholder.com/350x150">
</div>
<div class='image' data-timer="1000">
<img class='image' src="http://via.placeholder.com/350x150">
</div>
</section>
Run the snippet to see it in action.
So your loop would look something like:
<section class="images">
<?php foreach ($model->slides as $slide): ?>
<div class="image"<?= !empty($slide->timer) ? ' data-timer="'.$slide->timer.'"' : null ?>>
<img class="image" src="<?= $slide->image ? '/pictures/'.$slides->image : null ?>">
</div>
<?php endforeach ?>
</section>
I have a php file which is required many times, includes a small jquery snippet that is supposed to run at each instance the php file is included. However seems like jquery runs all at once in the end because I am getting variables value at once instead of at each instance. So my php file that includes another php file number of times is
base-features.php
<?php
$youtubelinks = array(
'0' => 'https://www.youtube.com/embed/NilASeqRsjw'
'1' => 'https://www.youtube.com/embed/eXG8PbwmUJw'
);
foreach($youtubelinks as $key => $val) {
$ytlink = $val;
require('youtubelink.php');
}
On my youtubelink.php I can see the $ytlink variable
<div id="page-corporate-video-overlay" class="page-corporate-video-overlay">
<div class="container">
<div class="row block">
<div class="col-md-12">
<?php print $ytlink ?>
<p><span class="video-play-icon"></span><p>
</div>
</div>
</div>
</div>
<div class="page-corporate-video">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="inner">
<iframe id="corporate-video" class="page-corporate-video-iframe" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</div>
<!--The jquery script I am having problem with-->
<script type="text/javascript">
jQuery(document).ready(function() {
var videoYoutube = "<?php print $ytlink; ?>"
$('.page-corporate-video-overlay').click(function() {
$('html, body').animate({
scrollTop: $(this).closest("div.page-corporate-video-overlay").offset().top-15
}, 500);
$(this).hide();
console.log(videoYoutube);
$(this).closest('div.base-feature').css({'background-image':'none','height':'auto'});
$(this).next('div.page-corporate-video').find('.page-corporate-video-iframe').attr('src',videoYoutube+"?controls=0&rel=0&showinfo=0&enablejsapi=1&autoplay=1&modestbranding=1&theme=light");
$(this).next('div.page-corporate-video').show();
});
});
So when I click on .page-corporate-video-overlay', I get two values of thevideoYoutube` variable. This is causing me problems to embed the right video onto the iframe as only last value gets embedded instead of each iframe getting relative youtube variable value during the each loop instance.
Thanks to #freedomn-m 's comment I refactored my code according to his suggestion.
Refactored youtubelink.php
Everything is almost the same except I added an extra attribute on the div.page-corporate-video-overlay of data-ytlink ="<?php print $ytlink;?>" and on my Jquery within my click function event I added
var videoYoutube = $(this).attr('data-ytlink');
Now I am able to embed videos correctly.
Iam trying to have 3 buttons, and when i press one, it will show the content of a php file. This is what i have done so far:
In the main Html file:
<div class="buttons">
<a class="showSingle" target="1">Logg</a>
<a class="showSingle" target="2">Saker</a>
<a class="showSingle" target="3">Rediger Kunde</a>
</div>
<div id="div1" class="targetDiv"><?php include 'php/loggselect.php'; ?></div>
<div id="div2" class="targetDiv">Saker</div>
<div id="div3" class="targetDiv">Rediger </div>
And later in the same file:
<script type="text/javascript">
jQuery(function(){
jQuery('.showSingle').click(function(){
jQuery('.targetDiv').hide();
jQuery('#div'+$(this).attr('target')).show();
});
});
</script>
Have two problems: When I reload the page, all 3 divs are showing, I have to press one of the "buttons" to only show the content of that spesific button.
The next and biggest problem is that this is working fine as long as it is plain text. But when I use <?php include 'php/loggselect.php'; ?> it will no longer show / hide. The php file should display a table with search result from my database. But it does not work when the php only contains `
echo 'testing';
?>` either. Any soulution?
Thanks!
Problem #1: You can do,
CSS: .hiddenDiv {display:none;}
And add this class to every div
$(function(){
$(".showSingle").eq(0).trigger("click");
});
Problem #2: Do
var _var1 = "variableone";
$("#div1").load('php/loggselect.php?v1='+_var1+'&v2='+_var1);
Don't do <?php ... ?>
i need help to passing row from mysql database into div popup window?
how do i passing product id into popup div which i called through View?
For Example I Want Like This
i want to fetch product details into `product quick view popup window`
through product `ID`?
Here My Code
<div class="latest_products_sec">
<div class="latest_products">
<div class="title_box">
</div>
<!--Latest Products Slider -->
<div class="latest_pro_box">
<h4>Latest Shirt's Collection</h4>
<div class="latest_products_slider">
<?php
$queryshirt=mysql_query("select image,id from products
where cid='1' LIMIT 5") or die ('die shirt query');
while($rowshirt=mysql_fetch_array($queryshirt))
{
echo '<ul>';
echo '<li><img src="admin/'.$rowshirt['image'].'"
width="225" height="300" alt="" />
View</li>';
echo '</ul>';?>
}
?>
#shirt Div Popup Window
<div id="shirt" class="proquickview">
<span class="close_btn" onclick="parent.jQuery.fancybox.close();">Close</span>
<h2 class="title">quick view</h2>
<div class="quickviewinfo">
<?php
// I Need To Get ID Here
echo $id=$_REQUEST['id'];
?>
<div class="quickviewinforight">
<div class="titlerow">
<h2>Latest Shirt's Collection</h2>
<div class="start_ratings">
<div class="start_rating">
</div>
</div>
<div>
<div class="quick_review">
<h3>Quick Discription</h3>
<p>TEST.</p>
</div>
<div class="qty_row">
<div class="qty_field">
<label>Select Quantity</label>
<span>
<select name="S">
<option>5</option>
</select>
</span>
</div>
<br class="clear" />
<span class="total_price">Price <strong>$88.00</strong>
<del>$102.00</del></span>
ADD TO CART
</div>
<div class="total_price_row">
</div>
</div>
</div>
</div>
Javascript For Popup Window
$(document).ready(function() {
$(".view_btn").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
});
$(document).ready(function(){
// Cufon Functions //
Cufon.replace ('.latest_products_slider ul li a.view_btn',{hover:true});
});
It's hard to tell what is wrong as you have only given part of the story.
Fundamentally you need:
Action by the user (usually a click) triggers AJAX call sending a unique ID onclick="updatefunction(this.id) in a SPAN or DIV will do the trick:
<SPAN onclick="updatefunction(this.id)" id="1234">Your Stuff to update</SPAN>
The JS function updatefunction must send the detail/ID to a separate PHP script (you can use the original but this just makes it clunky) which queries your database on the ESCAPED data you send.
Once the data is ready, the JS will update the window/pop it up.
AFAICS you are missing the extra bit that actually does the querying or not applying a suitable onclick.
Why not have a look at the excellent W3Schools Ajax tutorial - it will help though does not use jQuery.
So, first, a thanks to a guy named Marcel Gwerder, he wrote the code I am asking a question about. I WOULD write a comment or PM'ed him, but I felt the thread was dead (and people don't just look at old threads right? They can't be bumped either) and I didn't know how to PM People.
Look at this code
// Shop Stuff
var cart = [];
$(document).ready(function(){
var buttonTxt = '';
$(".buyinfo").click(function() {
//Store text and id of the selected element
var txt = $(this).siblings('.shopitemname').text();
var id = $(this).closest('.shopitem').attr('id');
if(!$(this).hasClass('added')) {
buttonTxt = $('.buyinfoname', this).text();
$('#box_item').text(txt);
cart[id] = txt;
//Change text
$('.buyinfoname', this).text('Added to cart - Click to remove');
$(this).addClass('added');
//Show and hide overlay
$('#confirmbox').show('normal').delay(2000).fadeOut();
} else {
delete(cart[id]);
$(this).removeClass('added');
$('.buyinfoname', this).text(buttonTxt);
}
console.log(cart);
alert(cart);
});
});
It is some Javascript.
Now for some HTML which was recommended by a commenter.
<div id="shop">
<input type="button" value="Go To Checkout" id="checkoutbutton" />
<div class="shopitem">
<p class="shopitemname">Orange Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem">
<p class="shopitemname">Black Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem">
<p class="shopitemname">Green Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem">
<p class="shopitemname">Blue Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem">
<p class="shopitemname">Yellow Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem">
<p class="shopitemname">Purple Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
</div>
</section>
<div id="confirmbox">
<p>The item was successfully added to your cart</p>
</div>
I was wondering how to send over the values in the CART variable to a new page that someone can click called "checkout.php". I was thinking AJAX from jquery or post from PHP but both are hard for me (I'm a noob coder) and I don't want to work hard on something that might not work out in the end.
Also, a question for Marcel (if he sees it) or a question for anyone who understands his code:
Why don't the values get in the cart, I did alert(cart) and it always displays empty alert box when there should be a value in cart.
Please assist me, and have a good day.
You can do this and I created a working JS fiddle example example. This is ONLY on the client side and you'd have to write the back end processing script because I'm not sure what you'd trying to do (save values in a database etc.).
Please look at the following JS fiddle:
http://jsfiddle.net/rDgUD/2/
You can use a .post command in jQuery:
$("#checkoutbutton").click(function () {
$.post("test.php", cart, function (data) {
//this is the reponse back from your PHP processing page that saved the variables in a database or however you were handling that.
alert("Data Loaded: " + data);
});
});
You can see how I handled the saving of the variables to your cart array in the JS fiddle. You add array elements with the .push functionality of jquery:
cart.push(id);
I also removed elements using the following code:
var removeItem = id; // item to remove
cart.splice($.inArray(removeItem, cart), 1);
Javascript runs on the users computer and PHP on the server.
So whilst you might want to use javascript to collect the data, I'm pretty sure you'll want to process the data with PHP, to avoid the user being able to interfere with it too easily.
"Think of your Ajax code as just another client to your server" from Security advice for jquery ajax data post?