Jump to content

Recommended Posts

I'd like to have a script that displays results I extracted from the database. But it should display these results one at a time, ie. One result displays for a few seconds and then it changes to another and continue looping through the results. Help would be really appreciated.

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

Thanks for the reply but, I don't really know Ajax. A good example of what I want can be seen on goal.com, where u have the recent news displayed in photos and these headlines are being displayed in a larger frame, one after the other. Can it ever be done with php?

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>

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.