3
Contributors
6
Replies
27
Views
3 Years
Discussion Span
Last Post by chaitu11
0

Are they in div or? Refresh whole page or?
You can use jQuery. For exaple:

<script type="text/javascript">
var autorefresh=setInterval(
function()
{
            $("#your_element").load("new_entries");
    }, 2000);
</script>

Edited by vinsbg

0

i want to refersh only divs they are in divs

Edited by chaitu11

0

how to refresh advertisements after every 2 sec in website using php

You would have to handle this client side because if you want PHP to take care of it, then the page would have to be reloaded every two seconds. That's not going to work. You need to do this using javascript, client side. The sample code above is just that. I wouldnt see how that code is going to work for you without any other knowledge of the page elements. so of course that's not going to work.

There isnt enough information to provide you with a solution at this time. Where are the ads you want to serve? Are they simply images? If so, with some javascript or jQuery, you can have all of the images downloaded at the time the page is accessed, then change the images every two seconds like a slideshow. Or, if you need to serve the content based on something else and you need your PHP code to make the decision on which ads to show, you can have AJAX on the client make a call back to the server, then have the server send back the information to the client to show the next ad, and so on...

0
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
setInterval("my_function();",1000); 

function my_function(){
  $('#time').load(location.href + ' #time');
  //alert('refresh');
}
</script>

<div id="time">

<?php
$con = mysqli_connect("localhost","root","","shantichakra");
$sel = mysqli_query($con,"select name from reg ORDER BY RAND() LIMIT 1");
$row = mysqli_fetch_array($sel);
echo $name = $row['name'];
?>

</div>

Edited by chaitu11

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.