change content every 10 sec
#1
Posted 13 June 2007 - 01:33 AM
i have a form so users can upload photos ... data is stored in database. I am looking for a simple script that will show the data from database and it changes every 10 sec or so ...
I looked on google, hotscripts and i couldnt find anything usefull ...
best regards,
heki
#2
Posted 13 June 2007 - 10:02 AM
For the random display every time someone accesses the site you would use something like this, and it would be along the lines of
$random = rand($selected = mysql_fetch_array($select));!!Please dont quote me on this, I have no idea if this is correct. Just giving an example of what I think!!
For the 10 second thing, im guessing it would need something like m_uwait, but I don't know what would be needed.
Edited by Korndawg, 13 June 2007 - 10:03 AM.
#3
Posted 13 June 2007 - 11:02 AM
You can populate the array normally and then shuffle it or manipulate it another way, or you can simply use RAND (this is relatively slow in comparison to the first method i mentioned but lets keep things simple).
Example:
$query = mysql_query('SELECT * FROM `table` ORDER BY RAND()') or die(mysql_error());
// LIMIT if you wish to...
For the 10 second "change" of content, well, you could use a javascript alternative but to be honest you could just use a refresh option (done, ironically using javascript, meta tags or since we're on the "php theme"....)
header('refresh: 5; url=' . $_SERVER['PHP_SELF']);
Hope that helps you put something together.
Matt
Edited by Matthew., 13 June 2007 - 11:03 AM.
#4
Posted 13 June 2007 - 10:11 PM
#5
Posted 14 June 2007 - 01:10 AM
i know about java, but it will be like a banner on friends page ... so only that banner needs to "refresh" every 10 sec or so ...
the problem with rand is that user has to refresh page to see the change ... do you think i can pull this of iwth a simple flash, php action on frame 1 and the flash keeps looping back to frame 1 after 10 sec, run the code and that way chagne the content?? sounds simple
thx for your replys
well swf solution doesnt work :S
i tried
header('refresh: 5; url=' . $_SERVER['PHP_SELF']);
works like i want yes, but in IE i get that stupid sound that page has been reloaded ...
Edited by Mr. Matt, 15 June 2007 - 05:21 AM.
#6
Posted 14 June 2007 - 12:05 PM
To simplify it for you, this would be the exact method you can use with the Prototype Framework.
Ajax.PeriodicalUpdater()
Simply connect it with a small PHP script that is randomly grabbing the data, and you're good to go.
#7
Posted 15 June 2007 - 01:52 AM
hm,
so i have a php function RANDOM LIMIT1 ... and if i run that script it shows me the stuff i need.
so do i just insert that script here? or show to that .php file?
i am a little lost
and where do i put this ajax in the end??
Edited by Mr. Matt, 15 June 2007 - 05:20 AM.
#8
Posted 15 June 2007 - 11:51 AM
Filenames are quite blunt, so you know their function.
homepage.php
<script type="text/javascript" language="javascript">
<!--
new Ajax.PeriodicalUpdater('image', 'ajax.php', {method: 'get', frequency: 10});
-->
</script>
<div id="image"><?php include 'ajax.php'; ?></div>
<noscript>You don't have javascript enabled/supported, so the image above won't rotate every ten seconds, sorry!</noscript>
ajax.php
// Database Connection Here
$query = mysql_query('SELECT * FROM `table` ORDER BY RAND() LIMIT 1') or die(mysql_error());
$result = mysql_fetch_array($query);
echo '<img src="'.$results['image_url'].'" alt="Random Image" />';
Notice how I also have the homepage.php include the ajax.php page into the div container. This is not only to show the very first image, but also as a back-up for those who might not have javascript enabled/supported, so they atleast get the first image. Also, the noscript tags will give them a message about it.
#9
Posted 15 June 2007 - 12:56 PM
#10
Posted 16 June 2007 - 10:12 AM
i guess we did something wrong, couse only include script works. ajax stuff doesnt show up!
<_<
any ideas?
#11
Posted 16 June 2007 - 10:59 AM
Do you have the Prototype library file attached with the document? You can't use methods from an undefined object...
Is it giving errors, what is it doing.
If it simply 'isnt doing anything' and you have the Prototype framework attached, you'll have to either give m your source or simply point me to your page.
#12
Posted 17 June 2007 - 01:23 PM
Quote
.no. do i just attache it like external .js file? i guess this will fix the problem
#14
Posted 18 June 2007 - 01:38 AM
it works pefectly in FF but in IE it only shows 1 image and keeps rotating that one ...
:wacko:
if i run a .php script which i use in IE and hit refresh button it does what it suppose to do.
But putting ajax to rotate the script ... Only loads 1 content in and rotats that 1 content
#15
Posted 11 September 2007 - 04:40 AM
i am back! Still trying to solve this problem and its getting on my nervers. Why? Ok, here is the thing ...
I have a php function:
$result = mysql_query("SELECT * FROM site WHERE st_status='1' ORDER BY RAND() LIMIT 1");
and than i use echo to show the info.
Than i use this
<script type="text/javascript" language="javascript">
<!--
new Ajax.PeriodicalUpdater('image', 'function.php', {method: 'get', frequency: 5});
-->
</script>
to update the info from sql ... Funny thing is that everything works in FireFox ... But in IE the first info that gets shown on the page, keeps rotating! It never changes the info send from sql!!
Also if i dont use LIMIT 1, than ajax shows all the images in database, but it never mix them up after ... In FireFox images do show on randomly ...
why is this??
#16
Posted 11 September 2007 - 06:11 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
