Jump to content

Automatically changing links after a few seconds


talk2toyin

Recommended Posts

You could do an ajax request to get the new link, one request by link. Or if the links in the database are not changing during the process, retrieve all the links at the beginning and replace the links using javascript or some javascript framework like jquery.

Edited by tirengarfio
Link to comment
Share on other sites

here's an example

 

<?php
   include("db_inc.php");
   $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE);
   $sql = "SELECT CONCAT(firstname,' ',lastname) as name
	    FROM employees";
   $res = $db->query($sql);
   $total = $res->num_rows;
   $data=array();
   while ($row = $res->fetch_row()) {
    $data[] = $row[0];
   }
   $arrayData = '"' . join('","', $data) . '"';   // data for JS array
?>

<html>
<head>
<meta name="generator" content="PhpED Version 8.1 (Build 8115)">
<title>sample</title>
<meta name="author" content="Barand">
<link rel="shortcut icon"  href="">
<script type="text/javascript">
   var count = 0;
   var limit = <?php echo $total ?>;
   var data = Array(<?php echo $arrayData ?>);

   function displayNext()
   {
    var el = document.getElementById("demo");
    el.innerHTML = data[count];
    ++count;
    if (count==limit) count = 0;
    setTimeout("displayNext()", 2000);
   }

   onload = function() {displayNext();}
</script>
</head>
<body>
<div id="demo" style="width: 200px; height: 60px; border: 1px solid gray; padding: 20px 5px;">
watch this space
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.