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

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>

i want to refersh only divs they are in divs

Did you try the code from above?

its not working

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...

<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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.