Hi, I was wondering if there was a script, or if someone could point me in the right direction. I am looking for a way to display html files randomally, that are located in a particular folder. Or, if I can store html in a mysql database, i know how to get php to randomally display that info. Thanks,
One way is you can get the files inside the particular directory which ends with .html extension. and then select a random one. You can call the require_once() function in php to call the random file selected or can use include() function. If you are trying to set the html data inside DB make sure you save the content as text or blob.
Thanks for the link and suggestions, that was very helpful. is there a performance difference by using either a random file, or storing it in a DB? I might just try it both ways and see which works better for me. Thanks,
function randomFile() { $files = glob("/path/to/dir/*.*"); return $files[array_rand($files, 1)]; } PHP: is more compact than the solution in the above URL. However, it would perhaps be best if you stored it in the DB and used order by rand() since the file based solutions require an array with all the filenames.. if you have loads of items it could eat up quite a bit of memory per request.
Well, i am not planning on having a lot of items, but I would like to plan for the future. Now that I annalize what I want to do, a db might be best, then I can display the same html file for lets say 3 days, and then display a different randomally selected one for another 3 days. Thanks all for the help. i will be in need of it again for other projects.
Our you can use : $file=array(); $file['1']="link to file 1"; . . . $file['n']="link to file n"; $random=random(1,n); $file_random=$file[$random]; PHP: