Insert Random Content - Page 1 - Post...

User 184085 Photo


Ambassador
1,707 posts

OK.. I'm going to try and explain what I'm thinking,

I'm working on a site for a friend, and in one column I want to insert three or so of their specialty drinks randomly from a set of 50 or so drinks.

So basically I'm thinking of some java or php type script that will pull in 2 or 3 "drink files" each time the page loads.

Google friendly would be a big plus.

Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 133269 Photo


Registered User
2,900 posts

php would do it just fine David :)

Mail me and i'll write you a script...
Have fun
~ Fe Pixie ~
User 133269 Photo


Registered User
2,900 posts

err - never mind the mail - someone else might find this useful too...

<?php
// comments array
$com[1]="comment 1";
$com[2]="comment 2";
$com[3]="comment 3";
$com[4]="comment 4";
$com[5]="comment 5";
$com[6]="comment 6";
$com[7]="comment 7";
$com[8]="comment 8";
$com[9]="comment 9";
$com[10]="comment 10";

// pull 3 comments (change the 3 to the number of comments you want to display)
for ($a=0; $a<3; $a++) {
// pick a random number between 1 and 10 (change the 10 if you have more or less comments)
$pull = rand(1,10);
// get the one that matches the random number from the list
$comment = $com[$pull];
// display it
echo "$comment<br />";
}

?>


dont forget to save the page with a .php extension to make it go :)
Have fun
~ Fe Pixie ~
User 184085 Photo


Ambassador
1,707 posts

OK, if I understand what is going on here, my $com listing would look like.

$com[1]="<h3 class="specialheading">Tropicana Banana</h3><p class="specialpara">Drift to the tropics with our specially selected milk steamed with Coconut, Banana and Rum Butter extracts, fresh whipped cream and chocolate sprinkles. </p>";


PS: thanks for this :)
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 117361 Photo


Ambassador
6,076 posts

Fe... don't know when and if, but it certainly looks worth keeping for future reference.
Thanks
:D
User 133269 Photo


Registered User
2,900 posts

david wilson wrote:
OK, if I understand what is going on here, my $com listing would look like.

$com[1]="<h3 class="specialheading">Tropicana Banana</h3><p class="specialpara">Drift to the tropics with our specially selected milk steamed with Coconut, Banana and Rum Butter extracts, fresh whipped cream and chocolate sprinkles. </p>";


PS: thanks for this :)


almost - inside the php quotes - you need to "escape" the html quotes by adding a \ in front of them

so your $com[1] should look like...
$com[1]="<h3 class=\"specialheading\">Tropicana Banana</h3><p class=\"specialpara\">Drift to the tropics with our specially selected milk steamed with Coconut, Banana and Rum Butter extracts, fresh whipped cream and chocolate sprinkles. </p>";

so that the php quotes and html quotes dont get muddled
Have fun
~ Fe Pixie ~
User 1948478 Photo


Senior Advisor
1,850 posts

I think I - too - am beginning to "like php"...!

Thank you for the inspiration, Fe :)
User 364143 Photo


Guest
5,410 posts

Fe Pixie wrote:
err - never mind the mail - someone else might find this useful too...


I certainly did. Can always add another script to the collection.

Thanks Fe, you're the bomb. :)
CoffeeCup... Yeah, they are the best!
User 133269 Photo


Registered User
2,900 posts

Per wrote:
I think I - too - am beginning to "like php"...!


how can ya not? - its soooooo darn useful :P
and the more you learn - the more useful it is...
Have fun
~ Fe Pixie ~
User 133269 Photo


Registered User
2,900 posts

ooo - everyone likes it - *runs off to add it to the snippet contest that ends... errr... soon....* :lol: :D
Have fun
~ Fe Pixie ~

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.