Jump to content


Random Generator


4 replies to this topic

#1 theJapster

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 09 July 2006 - 09:36 AM

Folks,
In my quest to learn PHP, I have came across something I could find rather useful! Basically I could do with finding out how (in php) I could create a 'program' where you put in a load of values and then press a button and it will pick one of those values and display it.

Or the reason I want it is I want a 'program' which would pick one different football team (from a list) and display it on the screen, each time I pressed a button.

Do you get me? Look forward to your response!

#2 Erik Bernskiold

    Jedi In Training

  • Members
  • PipPip
  • 422 posts
  • Gender:Male
  • Location:Gothenburg, Sweden
  • Interests:I love to do booth Web Design and Photography. Nothing beats a nice day out in the nature with the camera gear, getting loads of nice photos. I have been playing the flute for 6 years now and I love it, and I am playing the pipe organ as well. I also like to teach other people the in and outs of software such as the CS3 suite from Adobe.

Posted 09 July 2006 - 10:13 AM

You seems to be mixing net scripting and desktop programming, do you want a script which displays a new team each time you press a button on a website?

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 July 2006 - 12:11 PM

This could actually be done in nothing but PHP rather easily. Of course, having some HTML to display this so called "button" would help, but that's beside the point.

There are tons of tutorials on how to do this in the tutorial database here, more often then not, they are for random affiliates, but it's all the same thing.

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 09 July 2006 - 12:33 PM

ok...here is the most basic version of what you want just to start you off.

<?php

/* These are the teams: */

$team[] = 'team1';
$team[] = 'team2';

/* To add more use this:
@	
@  $team[] = 'team name';
@
*/

if(isset($_POST['press']))
{
  
	echo $team[array_rand($team, 1)]; //  '1' is the amount of teams you want.
}
else
{
  
	  echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
			<input type="submit" name="press" value="Press me!" />
			</form>';
}
?>

Shouldn't be anything there you cant figure out. If there is, post back :)

Edited by .Matt, 09 July 2006 - 12:46 PM.


#5 theJapster

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 09 July 2006 - 12:44 PM

Thanks Matt, that does the job fantastically!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users