...

View Full Version : what do i use for this little project?



timbo6585
04-21-2007, 04:59 AM
I want to make a list of random facts. Then I'd like to put them in a file so that they can be randomly pulled up at any time through a website. I have a pretty good basis in HTML and that's about it. So basically it would just be a little tiny blurb that changes everytime you refresh the page OR that just changes each day. I'm not sure how exactly to do this, can someone point me in the right direction? Much appreciated, thank you.

Tim

awsomejoe23
04-21-2007, 05:10 AM
You would need a simple little php script for that.
Here is a little program I made for my site. It will randomly generate a new item each time the page is loaded!
EX:

<?php
switch (rand(1,4)){
case "1":
echo "html goes here. This is item 1";
break;
case "2":
echo "html goes here. This is item 2!";
break;
case "3";
echo "html goes here. This is item 3";
break;
case "4";
echo"html goes here. This is item 4";
break;

}

?>
You can place html code in between the parenthesis. If you want to add or subtract options simply repeat, or delete part of the pattern. also at the very top where it says rand then 1,4 those are the numbers it will generate. You must have it so that the numbers will generate your highest "case".
EX:

<?php
switch (rand(1,5)){
case "1":
echo "html goes here. This is item 1";
break;
case "2":
echo "html goes here. This is item 2!";
break;
case "3";
echo "html goes here. This is item 3";
break;
case "4";
echo"html goes here. This is item 4";
break;
case "5";
echo"html goes here. This is item 5";
break;

}

?>
Noticed I had to change the numbers inside the rand function to correspond with the amount of cases I have.

P.S. don't forget to change your site from .html to .php

timbo6585
04-21-2007, 05:18 AM
thanks for the help!

i really don't know any PHP(although my forum is PHP based) but you did a good job of explaining it, it doesn't look to complicated. im going to give it a try, thanks for the help. by the way i am making this as a little program/script to sell here and there for probably 5 bucks, just wanted to make sure you don't have a problem with me using this.

thanks!

timbo6585
04-21-2007, 05:46 AM
I took the code and put it in a notepad document and saved it as a php file then opened it up in the browser just to give it a try, it didn't display anything. (It'll get obvious the more I speak that I don't know what I'm doing) So then I tried enclosing the "your html goes here" with <p></p>'s around the text thinking maybe it needed some html tags. that didn't work at all, it just displayed the whole entire code through the browser window then. im sorry i have no idea how to use php, but im sure im missing something simple here, i thought maybe if just fill in the blanks it'd work, what am i forgetting?

awsomejoe23
04-21-2007, 06:00 AM
This worked on my site http://www.awsomejoe23.heliohost.org/template/switcheroo.php

<html>
<head>
</head>
<body>
<?php
switch (rand(1,5)){
case "1":
echo "html goes here. This is item 1";
break;
case "2":
echo "html goes here. This is item 2!";
break;
case "3";
echo "html goes here. This is item 3";
break;
case "4";
echo"html goes here. This is item 4";
break;
case "5";
echo"html goes here. This is item 5";
break;

}

?>
</body>
</html>
Post your code so I can see any problems. and if you are doing it from your computer not on your server I don't think it will work as you don't have php installed. Make sure you try it on a server.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum