Jump to content

Random content selctor...


mrbananaman

Recommended Posts

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 :D

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.