Insert Random Content - Post ID 127196

User 364143 Photo


Guest
5,410 posts

Fe Pixie wrote:
and the more you learn - the more useful it is...


Indeed! :)

For example, you can modify the script to create a banner ad that displays a random image link.
CoffeeCup... Yeah, they are the best!
User 133269 Photo


Registered User
2,900 posts

here we go then - evolving slightly - bit more php - but a bit less html if you're looking for each item in the array to be formatted the same....

this is storing the item in a multilevel array

<?php
// comments array
$com[1]['title']="Tropicana Banana";
$com[1]['content']="Drift to the tropics with our specially selected milk steamed with Coconut, Banana and Rum Butter extracts, fresh whipped cream and chocolate sprinkles.";
$com[2]['title']="title 2";
$com[2]['content']="content 2";
$com[3]['title']="title 3";
$com[3]['content']="content 3";
$com[4]['title']="title 4";
$com[4]['content']="content 4";


// 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,4);
// get the one that matches the random number from the list
$title = $com[$pull]['title'];
$content = $com[$pull]['content'];
// display it
echo "<h3 class=\"specialheading\">$title</h3><p class=\"specialpara\">$content </p>";
}
?>

you could add any number of fields in the array
- eg. $com[1]['link'] = "http://link.to.com"; in the array with
$link = $com[$pull]['link']; and
<a href=\"$link\">$title</a> in the echo statement

why type out the html over and over again when the php can do it for you ;)
Have fun
~ Fe Pixie ~
User 184085 Photo


Ambassador
1,707 posts

You know Fe, with you in NZ and me in CA I'm awake when you are asleep and visa versa.... if we work together we can get websites don in half the time.. crushing the competition... how about it, you be the programmer and I will be the accountant ;-)
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 133269 Photo


Registered User
2,900 posts

oh heck yeah - an accountant would make life so much easier!!!
Have fun
~ Fe Pixie ~
User 184085 Photo


Ambassador
1,707 posts

Great 'Bull n' Ewe' web sanity solutions it is...
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 117361 Photo


Ambassador
6,076 posts

Fe... so long as he had something to count in his accounting!!!
:(
User 133269 Photo


Registered User
2,900 posts

theres sure not much left to count after my accountants have had their share - rude buggers - charged me $700 bucks for a company that only does 5-10 transactions a month - and $6G for the bigger company and in the middle for the middling ones :( AND filed all 6 returns late so i got late fees on top of tax :( *mutters grumpily* not in my good books them :mad:
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.