mrbananaman Posted November 17, 2010 Share Posted November 17, 2010 Hi I'm wondering how I would go by making some sort of scrip for my website that loads random content from different files on my web server. Preferably php coding and maybe some mysql coding for an example I would like to have different folders on my web server lets say I have ( File 1 ) and in file 1 I have files named "cover.jpg" and "description.txt" and maybe some other files too and the same thing in other files on the web server So how would I go by making some thing that can load up these different files on the web server, like I said that will load up the content in each of the files every time the page refreshes or press of a button. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/218905-random-content-selctor/ Share on other sites More sharing options...
defeated Posted November 17, 2010 Share Posted November 17, 2010 I think the easiest way is to have a mysql db that stores the names and locations of the files. Then you can use $query=mysql_query("SELECT * FROM table ORDER BY RAND() LIMIT 1"); to extract one random file. I would put everything into the db though. . . and just have your jpegs in files. That means you don't even have to read any text files... just get it directly from the DB. Your columns could be something like "jpeg_location", "jpeg_alt_txt" and "description_text". That way you just have to do something with your mysql query like while($result=mysql_fetch_array($query)) { $jpeg_location=$result['jpeg_location']; $jpeg_alt_txt=$result['jpeg_alt_txt']; $description_text=$result['description_text']; echo "<img src='".$jpeg_location."' alt='".$jpeg_alt_txt."' /><br /><p>".$description_text."</p>"; Of course you could make it prettier than that but you get the idea. Quote Link to comment https://forums.phpfreaks.com/topic/218905-random-content-selctor/#findComment-1135275 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.