talk2toyin Posted February 14, 2013 Share Posted February 14, 2013 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. Quote Link to comment Share on other sites More sharing options...
tirengarfio Posted February 14, 2013 Share Posted February 14, 2013 (edited) 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 February 14, 2013 by tirengarfio Quote Link to comment Share on other sites More sharing options...
talk2toyin Posted February 14, 2013 Author Share Posted February 14, 2013 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 14, 2013 Share Posted February 14, 2013 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> Quote Link to comment Share on other sites More sharing options...
talk2toyin Posted February 14, 2013 Author Share Posted February 14, 2013 Thanks Barand...I'll be sure to get back to you when I try that out. My PC just went bad. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2013 Share Posted February 14, 2013 My PC just went bad. Keep an eye on those expiration dates! Don't want a sour PC. :-P Quote Link to comment Share on other sites More sharing options...
talk2toyin Posted February 14, 2013 Author Share Posted February 14, 2013 Yeah Jessica, I'll keep that in mind when getting a new one. Mine's way past it's expiry date. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.