I have started learning php and would like to create some dynamic rotating text on the main page. An example of this is shown at http://www.webmaster-toolkit.com where a different site is shown each time in "Site of the Moment".
I basically want to know how to do a really simple version of this as i take it this version is done using some form of datebase.
Quite simply i want to have a directory containing a number of different files (for example text files) each text file contains the site description and the link to the site. Each time the index page is viewed and/or refreashed a different/random text file from the directory in question is selected.
The content of which is then shown in a specified area on the index page.
Any help for a newbie???
Rotating Content
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
SELECT `website`,`websitedescription` WHERE `id` = rand(`ID`) LIMIT 1i support phenom's advice about using databases. anyway if it's inevitable, you can store (or dynamically fill) the list of the file names in an array and generate a random index in order to access a random name and include it
or
having named the files systematically (file0001.txt, file0002.txt, etc), generate a random index and compose the included file name with it ("file".$randomIndex.".txt");
or
having named the files systematically (file0001.txt, file0002.txt, etc), generate a random index and compose the included file name with it ("file".$randomIndex.".txt");
Oh...I learn something new everyday!Phenom wrote:Code: Select all
SELECT `website`,`websitedescription` WHERE `id` = rand(`ID`) LIMIT 1
If you want to use text files use a loop to go if (file_exists($file))
that will get a list of files in that directory, then use the rand() function to get a random #
for instance:
file1
file2
file3
then in php go
while(file_exists(file))
or something like that then
$file = "file" . rand(1,$x);
Where $x is the # for the last file there is
(A database would be alot better)
that will get a list of files in that directory, then use the rand() function to get a random #
for instance:
file1
file2
file3
then in php go
while(file_exists(file))
or something like that then
$file = "file" . rand(1,$x);
Where $x is the # for the last file there is
(A database would be alot better)