I am attempting to write an Online Baseball Pitching Simulator with PHP. What should happen is:
The user selects a pitcher
The user selects their first pitch
The PHP script pulls a random quote (Ball , Strike, Walk)out of a textfile and displays it
If the pitch is a strike, a strike variable should increment, if the pitch is a ball, a ball variable should increment. [/list=1]
The first three things happen successfully, but the variables don't increment properly. The code that I am currently using is attached
try to echo the values of $strike, $ball, $walk
after global $strike, $ball, $walk;
does a static variable retain its value when a page is submitted, i think u need to use sessions ??
reg kevin
Thanks for your help...will try echoing.
You will probably want to implement sessions in order to keep track of the variables each pitch.
session_start(); // put your logic code here to determine ball, strike, hit, etc... // let's say that your result was called $call switch($call) { case 'ball': $_SESSION['balls++']; break; case 'strike': $_SESSION['strikes++']; break; ...etc, etc through all possible variations.
Where should I put the session_start() part? I tried putting it at the top of the page, but that didn't work. I tried putting it in my umpire() function, but that didn't work.
Something about: Warning: Cannot send session cache limiter - headers already sent (output started at /var/www/html/php/baseball.php:10) in /var/www/html/php/baseball.php on line 47
you have to make sure that NOTHING not even on single space of output is in your file before calling session_start()
it has to be ther first thing sent. The reason is that PHP automatically sends the text/html headers to the screen upon your first output, which will cause an error when session_start tries to set a cookie
Hurrah! It worked. All I have to do is reset the $_SESSION variables whenever a certain page is accessed. Not a problem.
Thanks all for your help.