I am creating a web page where someone can visit it. They type a question in a field and click a button, and a response is passed back to them. (Kind of like a magic 8 ball).
What I’m trying to do is set it up something like this:
http://img585.imageshack.us/img585/997/layoutoi.png
I’m still new to hand-coding things – I have a book on HTML/CSS and one on PHP, which lay still unread, so I’ll probably need a step-by-step process. (I have a host and everything, so that’s already taken care of.) Thanks in advance!
To do it without a page load (i.e. immediately after the button click), you’ll have to do it in Javascript (working jsfiddle example here)
To do this instead in PHP (which will require a new page load), you could do this:
First, we create an array (‘list’) of random things and store it in the variable
$randomThings.Elements in an array can be accessed using
$variableName[$index]— in this case, the indices will simply be 0,1,2,3,4,5,6.The reason this one-liner (beginning with ‘echo’) works is,
mt_randis going to return a random number between 0 and 6, so it’ll grab a random element from the $randomThings array.echowill then spit it to the page.